question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Undefined access token

See original GitHub issue

After 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:closed
  • Created 3 years ago
  • Comments:20 (10 by maintainers)

github_iconTop GitHub Comments

2reactions
wtrockicommented, Aug 24, 2020

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)

0reactions
wtrockicommented, Mar 29, 2022

what do you mean “use a public client from keycloak”?

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.

are you saying that context.kauth.accessToken should not contain the Bearer access token?

That would be part of the keycloak node.js library logic. All we do here is export this logic to graphql layer.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found