diff --git a/README.md b/README.md index 6f4d7c09..cc082772 100644 --- a/README.md +++ b/README.md @@ -138,6 +138,7 @@ type GoCloak interface { LoginClient(ctx context.Context, clientID, clientSecret, realm string) (*JWT, error) LoginClientSignedJWT(ctx context.Context, clientID, realm string, key interface{}, signedMethod jwt.SigningMethod, expiresAt *jwt.Time) (*JWT, error) LoginAdmin(ctx context.Context, username, password, realm string) (*JWT, error) + LoginAdminOtp(ctx context.Context, username, password, totp, realm string) (*JWT, error) RefreshToken(ctx context.Context, refreshToken, clientID, clientSecret, realm string) (*JWT, error) DecodeAccessToken(ctx context.Context, accessToken, realm, expectedAudience string) (*jwt.Token, *jwt.MapClaims, error) DecodeAccessTokenCustomClaims(ctx context.Context, accessToken, realm, expectedAudience string, claims jwt.Claims) (*jwt.Token, error) diff --git a/client.go b/client.go index ccff45fc..6b13da43 100644 --- a/client.go +++ b/client.go @@ -548,6 +548,17 @@ func (g *GoCloak) LoginAdmin(ctx context.Context, username, password, realm stri }) } +// LoginAdminOtp performs a login with Admin client and OTP token +func (g *GoCloak) LoginAdminOtp(ctx context.Context, username, password, totp, realm string) (*JWT, error) { + return g.GetToken(ctx, realm, TokenOptions{ + ClientID: StringP(adminClientID), + GrantType: StringP("password"), + Username: &username, + Password: &password, + Totp: &totp, + }) +} + // LoginClient performs a login with client credentials func (g *GoCloak) LoginClient(ctx context.Context, clientID, clientSecret, realm string, scopes ...string) (*JWT, error) { opts := TokenOptions{ diff --git a/go.mod b/go.mod index cde01123..3a21081b 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/Nerzal/gocloak/v13 +module github.com/oyviaase/gocloak/v13 go 1.18