-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add RecoveryCode endpoint #151
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,6 +40,7 @@ type KeycloakClient interface { | |
SendVerifyEmail(accessToken string, realmName string, userID string, paramKV ...string) error | ||
ExecuteActionsEmail(accessToken string, realmName string, userID string, actions []string, paramKV ...string) error | ||
SendNewEnrolmentCode(accessToken string, realmName string, userID string) (kc.SmsCodeRepresentation, error) | ||
CreateRecoveryCode(accessToken string, realmName string, userID string) (kc.RecoveryCodeRepresentation, error) | ||
SendReminderEmail(accessToken string, realmName string, userID string, paramKV ...string) error | ||
GetRoles(accessToken string, realmName string) ([]kc.RoleRepresentation, error) | ||
GetRole(accessToken string, realmName string, roleID string) (kc.RoleRepresentation, error) | ||
|
@@ -81,6 +82,7 @@ type Component interface { | |
SendNewEnrolmentCode(ctx context.Context, realmName string, userID string) (string, error) | ||
SendReminderEmail(ctx context.Context, realmName string, userID string, paramKV ...string) error | ||
ResetSmsCounter(ctx context.Context, realmName string, userID string) error | ||
RecoveryCode(ctx context.Context, realmName string, userID string) (string, error) | ||
GetCredentialsForUser(ctx context.Context, realmName string, userID string) ([]api.CredentialRepresentation, error) | ||
DeleteCredentialsForUser(ctx context.Context, realmName string, userID string, credentialID string) error | ||
GetRoles(ctx context.Context, realmName string) ([]api.RoleRepresentation, error) | ||
|
@@ -661,6 +663,22 @@ func (c *component) ResetSmsCounter(ctx context.Context, realmName, userID strin | |
return nil | ||
} | ||
|
||
func (c *component) RecoveryCode(ctx context.Context, realmName, userID string) (string, error) { | ||
var accessToken = ctx.Value(cs.CtContextAccessToken).(string) | ||
|
||
recoveryCodeKc, err := c.keycloakClient.CreateRecoveryCode(accessToken, realmName, userID) | ||
|
||
if err != nil { | ||
c.logger.Warn(ctx, "err", err.Error()) | ||
return "", err | ||
} | ||
|
||
// store the API call into the DB | ||
c.reportEvent(ctx, "RECOVERY_CODE", database.CtEventRealmName, realmName, database.CtEventUserID, userID) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. CREATE_RECOVERY_CODE ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
|
||
return *recoveryCodeKc.Code, err | ||
} | ||
|
||
func (c *component) GetCredentialsForUser(ctx context.Context, realmName string, userID string) ([]api.CredentialRepresentation, error) { | ||
var accessToken = ctx.Value(cs.CtContextAccessToken).(string) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't forget to revert this before merging