Skip to content

Instantly share code, notes, and snippets.

@anumber8
Forked from alvistar/keycloak.ts
Created Oct 10, 2021
Embed
What would you like to do?
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