Skip to content

Commit

Permalink
Make logoutUrl building more reliable
Browse files Browse the repository at this point in the history
  • Loading branch information
francois-roget committed Dec 23, 2022
1 parent e4bd6b7 commit 8a97167
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
7 changes: 5 additions & 2 deletions keycloak.js
Original file line number Diff line number Diff line change
Expand Up @@ -403,11 +403,14 @@ Keycloak.prototype.loginUrl = function (uuid, redirectUrl) {
Keycloak.prototype.logoutUrl = function (redirectUrl, idTokenHint) {
const url = new URL(this.config.realmUrl + '/protocol/openid-connect/logout')

if (redirectUrl && idTokenHint) {
url.searchParams.set('id_token_hint', idTokenHint)
if (redirectUrl) {
url.searchParams.set('post_logout_redirect_uri', redirectUrl)
}

if (idTokenHint) {
url.searchParams.set('id_token_hint', idTokenHint)
}

return url.toString()
}

Expand Down
2 changes: 2 additions & 0 deletions test/unit/keycloak-object-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ test('Should verify if login URL has the default scope value.', t => {

test('Should verify if logout URL has the configured realm.', t => {
t.equal(kc.logoutUrl().indexOf(kc.config.realm) > 0, true)
t.equal(kc.logoutUrl('redirectURI').indexOf('redirectURI') >0, true)
t.equal(kc.logoutUrl('redirectURI', 'hint').indexOf('hint') >0, true)
t.end()
})

Expand Down

0 comments on commit 8a97167

Please sign in to comment.