I’m using this auth-module with Keycloak.
My configuration in nuxt.config.js:
JavaScript
x
16
16
1
keycloak: {
2
_scheme: 'oauth2',
3
client_id: 'client-bo',
4
userinfo_endpoint: 'SERVER/protocol/openid-connect/userinfo',
5
authorization_endpoint: 'SERVER/protocol/openid-connect/auth',
6
//userinfo_endpoint: false,
7
access_type: 'offline',
8
access_token_endpoint: 'SERVER/protocol/openid-connect/token',
9
//response_type: 'code',
10
response_type: 'token id_token',
11
token_type: 'Bearer',
12
token_key: 'access_token',
13
scope: ['openid', 'profile', 'email'],
14
redirect_uri: 'http://127.0.0.1:3000/'
15
}
16
The connection is OK.
When I click on the “connect” button, I am redirected to my Keycloak environment. Once authenticated by Keycloak, I am redirected to my nuxt.js application.
However, the problem is that my store is empty. Do you have any ideas about what causes this problem?
loggedIn
: is always false
user
: is always null
Can you tell me why it doesn’t work?
Advertisement
Answer
I had similar issue, and was finally able to get it to work with the following configuration:
package.json
JavaScript
1
2
1
"@nuxtjs/auth-next": "5.0.0-1607534757.1122b76"
2
nuxt-config.json
JavaScript
1
32
32
1
auth: {
2
keycloak: {
3
scheme: 'oauth2',
4
endpoints: {
5
authorization: `${process.env.KEYCLOAK_HOST}/auth/realms/${process.env.KEYCLOAK_REALM}/protocol/openid-connect/auth`,
6
userInfo: `${process.env.KEYCLOAK_HOST}/auth/realms/${process.env.KEYCLOAK_REALM}/protocol/openid-connect/userinfo`,
7
token: `${process.env.KEYCLOAK_HOST}/auth/realms/${process.env.KEYCLOAK_REALM}/protocol/openid-connect/token`,
8
logout: `${process.env.KEYCLOAK_HOST}/auth/realms/${process.env.KEYCLOAK_REALM}/protocol/openid-connect/logout?redirect_uri=` + encodeURIComponent(String(process.env.HOME_URI))
9
},
10
token: {
11
property: 'access_token',
12
type: 'Bearer',
13
name: 'Authorization',
14
maxAge: 1800 // Can be dynamic ?
15
},
16
refreshToken: {
17
property: 'refresh_token',
18
maxAge: 60 * 60 * 24 * 30 // Can be dynamic ?
19
},
20
responseType: 'code',
21
grantType: 'authorization_code',
22
clientId: process.env.KEYCLOAK_CLIENT_ID,
23
scope: ['openid', 'profile', 'email'],
24
codeChallengeMethod: 'S256',
25
},
26
redirect: {
27
logout: '/',
28
callback: '/',
29
home: '/dashboard'
30
},
31
}
32
Login function:
JavaScript
1
4
1
login() {
2
this.$auth.loginWith("keycloak");
3
},
4
I had seen that GitHub had issues reported on the Nuxt Auth module, but was able to get it to work with this configuration. Hope this helps someone.