Skip to content

Commit

Permalink
[CLOUDTRUST-3191] Add method to logout a user from all his sessions
Browse files Browse the repository at this point in the history
  • Loading branch information
fperot74 committed May 5, 2021
1 parent 6fbfbe6 commit 09b5275
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
7 changes: 7 additions & 0 deletions api/credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const (
labelPath = credentialIDPath + "/label"
moveFirstPath = credentialIDPath + "/moveToFirst"
moveAfterPath = credentialIDPath + "/moveAfter/:previousCredentialID"
logoutPath = userIDPath + "/logout"
// Paper card API
papercardPath = "/auth/realms/:realm/papercard"
resetFailuresPath = papercardPath + "/users/:userId/credentials/:credentialId/resetFailures"
Expand All @@ -27,6 +28,12 @@ func (c *Client) ResetPassword(accessToken string, realmName, userID string, cre
return c.put(accessToken, url.Path(resetPasswordPath), url.Param("realm", realmName), url.Param("id", userID), body.JSON(cred))
}

// Logout all sessions of the user.
func (c *Client) LogoutAllSessions(accessToken string, realmName, userID string) error {
var _, err = c.post(accessToken, nil, url.Path(logoutPath), url.Param("realm", realmName), url.Param("id", userID))
return err
}

// GetCredentials returns the list of credentials of the user
func (c *Client) GetCredentials(accessToken string, realmName string, userID string) ([]keycloak.CredentialRepresentation, error) {
var resp = []keycloak.CredentialRepresentation{}
Expand Down
3 changes: 1 addition & 2 deletions api/keycloak_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,7 @@ func (c *Client) GetToken(realm string, username string, password string) (strin

var unmarshalledBody map[string]interface{}
{
var err error
err = resp.JSON(&unmarshalledBody)
var err = resp.JSON(&unmarshalledBody)
if err != nil {
return "", errors.Wrap(err, keycloak.MsgErrCannotUnmarshal+"."+keycloak.Response)
}
Expand Down

0 comments on commit 09b5275

Please sign in to comment.