Undefined access token
See original GitHub issueAfter calling const keycloak = new Keycloak( { … } ) with my configurations (i believe secret should be inside credentials - credentials: {secret: …} )
In my case my ApolloServer is like this
const apolloServer = new ApolloServer({ async context({ connection, req }) { const context = { …contextFromOptions };
// For a GraphQL subscription WebSocket request, there is no `req`
if (connection) return context;
await createDataLoaders(context);
context.kauth = new KeycloakContext({ req });
console.log(context.kauth.accessToken);
return context;
},
debug: options.debug || false,
formatError: getErrorFormatter(),
schema,
subscriptions,
introspection: config.GRAPHQL_INTROSPECTION_ENABLED,
playground: config.GRAPHQL_PLAYGROUND_ENABLED
});
I put a ocnsole log to view accessToken in context but it’s returning undefined. how can i debug and know that request is being made and view the keycloak response?
Issue Analytics
- State:
- Created 3 years ago
- Comments:20 (10 by maintainers)
Top Results From Across the Web
accessToken is undefined while user is logged in #2404
My issue is that calling getSession (sometimes) returns a session without the accessToken. debug:["current session: ",{"user":{"name":"Zied ...
Read more >Undefined X-access-token (jwt) - node.js
Undefined X-access-token (jwt) · First check that localStorage has stored the value of the token if the value is not stored for that...
Read more >Access-token is undefined after adding roles after post- ...
now if you try to access token it shows it is undefined. export const config = { authRequired: false, auth0Logout: true, secret: "some...
Read more >Undefined refresh token - OAuth/OIDC
Hello, I can't get a refresh token. It returns undefined. ... Takes a token, and returns a new token with updated * `accessToken`...
Read more >Undefined token issue when refreshing a new bearer token
I have an application that goes through the login page with username and password credentials and then has a get request with ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

The access token will not be available in the context method - it will be available in resolvers like demoed in the example applications. The context method is used to create object and it is not used to authenticate or have info about user.
It might happen that request is missing access token. This usually happens when we forget to add keycloak middleware/protect graphql route.
Also it is worth to include version of the keycloak adapter that is being used. Some issues with old adapters might happen (we also did not tested version 11 of the adapter)
Keycloak have two client types. Bearer and Public. Bearer client is used only for backends to check token - it doesn’t provide login logic/session etc.
That would be part of the keycloak node.js library logic. All we do here is export this logic to graphql layer.