Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@anumber8
Forked from alvistar/keycloak.ts
Created October 10, 2021 11:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anumber8/a024464bc355b5746b6126aaf9301f56 to your computer and use it in GitHub Desktop.
Save anumber8/a024464bc355b5746b6126aaf9301f56 to your computer and use it in GitHub Desktop.
Nuxtjs Logout Fix for Keycloak
import Oauth2Scheme from '@nuxtjs/auth-next/dist/schemes/oauth2'
import { encodeQuery } from '@nuxtjs/auth-next/dist/utils'
export default class KeycloakScheme extends Oauth2Scheme {
logout () {
if (this.options.endpoints.logout) {
const opts = {
client_id: this.options.clientId,
post_logout_redirect_uri: this._logoutRedirectURI
}
const url = this.options.endpoints.logout + '?' + encodeQuery(opts)
window.location.replace(url)
}
return this.$auth.reset()
}
}
build: {
transpile: ['@nuxtjs/auth-next'],
},
auth: {
redirect: {
callback: '/callback'
},
strategies: {
keycloak: {
scheme: '~/plugins/keycloak.ts',
endpoints: {
authorization: 'http://localhost:8081/auth/realms/vue/protocol/openid-connect/auth',
token: 'http://localhost:8081/auth/realms/vue/protocol/openid-connect/token',
userInfo: 'http://localhost:8081/auth/realms/vue/protocol/openid-connect/userinfo',
logout: 'http://localhost:8081/auth/realms/vue/protocol/openid-connect/logout'
},
token: {
property: 'access_token',
type: 'Bearer'
},
codeChallengeMethod: 'S256',
scope: ['openid', 'profile', 'email'],
accessType: 'offline',
responseType: 'code',
clientId: 'vue-client',
grantType: 'authorization_code'
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment