You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Using KeycloakProvider with local Keycloak 19 (quarkus) via docker on localhost
Reproduction
Due to mandatory keycloak reproduction is not possible, you have to set up a local keycloak with realm, public client and many client roles to be added to a test user.
Describe the bug
Due to my token endpoint ( /api/token ) for graphql I need the access_token of keycloak in my token, so I added it in the jwt callback. if I don't add the access_token in the jwt callback it also isn't present in getServerToken.
If the header is small because the user doesn't have many client roles assigned everything works fine, getServerToken returns the token as expected, but If I add more client roles resulting in a header larger than the default size or add the refresh_token to the token (which I need for other purposes) the getServerToken returns null, no error message given.
On the client side everything is fine.
If I add both tokens to the session via the session callback the tokens are present.
This is my /server/api/auth/[...].ts :
import{NuxtAuthHandler}from"#auth";importKeycloakProviderfrom"@auth/core/providers/keycloak"importtype{AuthConfig}from"@auth/core/types"import{jwtDecode}from"jwt-decode";construntimeConfig=useRuntimeConfig()asyncfunctiongetMyRoles(token: string){constdecodedToken=awaitjwtDecode(token)if(decodedToken.resource_access["mytestclient"].roles){returndecodedToken.resource_access["mytestclient"].roles}else{return[]}}exportconstauthOptions: AuthConfig={secret: "1234",<-dummyentry(derivedfromsidebase),thisisapublicclient
providers: [KeycloakProvider({clientId: "mytestclient, clientSecret: "1234", <- dummy entry (derived from sidebase), this is a public client issuer: "http://localhost:8080/realms/testrealm",})],callbacks: {asyncjwt({ token, account, user, trigger, session }){if(token&&user&&account&&account.access_token&&trigger==="signIn"){token.access_token=account.access_token;token.refresh_token=account.refresh_token;returnPromise.resolve(token);}if(token&&trigger===undefined){returnPromise.resolve(token);}returnPromise.resolve(token);},asyncsession({ session, token, user }){consttokenRoles=awaitgetMyRoles(token.access_token)session.roles=tokenRolessession.token=tokenreturnPromise.resolve(session)}}}// @ts-ignoreexportdefaultNuxtAuthHandler(authOptions,runtimeConfig)
I'm not sure if this is an issue of @auth/core 0.17.0 or the current version of this module, but this bug is present making the lib unusable on server side for us. In our application users can have many client roles and composite client roles (which is also working perfectly fine with nuxt2 and the auth module from nuxt), thus reducing the client roles is not an option.
This is clearly a bug. ;)
Additional context
asyncsession({ session, token, user }){consttokenRoles=awaitgetMyRoles(token.access_token)session.roles=tokenRolessession.token=token<=thisisaworkaroundtoaccessthetokenviagetServerSessiononserverside,butnosolutionforthisbug;)returnPromise.resolve(session)}
Logs
see description of the bug
The text was updated successfully, but these errors were encountered:
mpgalaxy
changed the title
getServerToken returns null if headers size exceeds default size
getServerToken returns null if header size exceeds default size
Jan 25, 2024
Environment
Reproduction
Due to mandatory keycloak reproduction is not possible, you have to set up a local keycloak with realm, public client and many client roles to be added to a test user.
Describe the bug
Due to my token endpoint (
/api/token
) for graphql I need the access_token of keycloak in my token, so I added it in thejwt callback
. if I don't add the access_token in the jwt callback it also isn't present ingetServerToken
.If the header is small because the user doesn't have many client roles assigned everything works fine,
getServerToken
returns the token as expected, but If I add more client roles resulting in a header larger than the default size or add the refresh_token to the token (which I need for other purposes) thegetServerToken
returnsnull
, no error message given.On the client side everything is fine.
If I add both tokens to the session via the session callback the tokens are present.
This is my
/server/api/auth/[...].ts
:And this is my
/server/api/token.get.ts
:With a large access_token or the refresh_token present (=>large header size) I get this:
I'm not sure if this is an issue of
@auth/core 0.17.0
or the current version of this module, but this bug is present making the lib unusable on server side for us. In our application users can have many client roles and composite client roles (which is also working perfectly fine with nuxt2 and the auth module from nuxt), thus reducing the client roles is not an option.This is clearly a bug. ;)
Additional context
Logs
The text was updated successfully, but these errors were encountered: