Skip to content

Commit e7751bd

Browse files
authored
Merge pull request #34 from vshn/fix/logout
Fix logout call to not use privileged endpoint
2 parents 834a16b + b24be52 commit e7751bd

File tree

4 files changed

+15
-11
lines changed

4 files changed

+15
-11
lines changed

keycloak/ZZ_mock_gocloak_test.go

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

keycloak/client.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ func (errs *MembershipSyncErrors) Error() string {
114114
// This keeps the mock at a more reasonable size
115115
type GoCloak interface {
116116
LoginAdmin(ctx context.Context, username, password, realm string) (*gocloak.JWT, error)
117-
LogoutUserSession(ctx context.Context, accessToken, realm, session string) error
117+
LogoutPublicClient(ctx context.Context, clientID, realm, accessToken, refreshToken string) error
118118

119119
CreateGroup(ctx context.Context, accessToken, realm string, group gocloak.Group) (string, error)
120120
CreateChildGroup(ctx context.Context, accessToken, realm, groupID string, group gocloak.Group) (string, error)
@@ -302,7 +302,8 @@ func (c Client) login(ctx context.Context) (*gocloak.JWT, error) {
302302
}
303303

304304
func (c Client) logout(ctx context.Context, token *gocloak.JWT) error {
305-
return c.Client.LogoutUserSession(ctx, token.AccessToken, c.loginRealm(), token.SessionState)
305+
// `admin-cli` is the client used when authenticating to the admin API
306+
return c.Client.LogoutPublicClient(ctx, "admin-cli", c.loginRealm(), token.AccessToken, token.RefreshToken)
306307
}
307308

308309
func (c Client) getGroup(ctx context.Context, token *gocloak.JWT, toSearch Group) (*gocloak.Group, error) {

keycloak/client_login_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,11 @@ func TestLogin(t *testing.T) {
2626
Return(&gocloak.JWT{
2727
SessionState: "session",
2828
AccessToken: "token",
29+
RefreshToken: "refresh",
2930
}, nil).
3031
AnyTimes()
3132
mKeycloak.EXPECT().
32-
LogoutUserSession(gomock.Any(), "token", "target-realm", "session").
33+
LogoutPublicClient(gomock.Any(), "admin-cli", "target-realm", "token", "refresh").
3334
Return(nil).
3435
AnyTimes()
3536

@@ -55,10 +56,11 @@ func TestLogin_WithLoginRealm(t *testing.T) {
5556
Return(&gocloak.JWT{
5657
SessionState: "session",
5758
AccessToken: "token",
59+
RefreshToken: "refresh",
5860
}, nil).
5961
AnyTimes()
6062
mKeycloak.EXPECT().
61-
LogoutUserSession(gomock.Any(), "token", "login-realm", "session").
63+
LogoutPublicClient(gomock.Any(), "admin-cli", "login-realm", "token", "refresh").
6264
Return(nil).
6365
AnyTimes()
6466

keycloak/suite_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@ func mockLogin(mgc *MockGoCloak, c Client) {
1515
Return(&gocloak.JWT{
1616
SessionState: "session",
1717
AccessToken: "token",
18+
RefreshToken: "refresh",
1819
}, nil).
1920
AnyTimes()
2021
mgc.EXPECT().
21-
LogoutUserSession(gomock.Any(), "token", c.Realm, "session").
22+
LogoutPublicClient(gomock.Any(), "admin-cli", c.Realm, "token", "refresh").
2223
Return(nil).
2324
AnyTimes()
2425
}

0 commit comments

Comments
 (0)