-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unable to set accessToken in signIn callback #894
Comments
Hi there! You could fetch the access token in the jwt callback as well. In addition to user, you will also get the account in From your example, it looks like you only need the account ID. I am curious though, do you take other measures to get hold of an access token besides sending an account ID? please prove me wrong but from your code example, it looks like I could get an excess token for a user, if I know their ID. A standard way of getting an access token is using OAuth authorization flow, which Relevant documentation: https://auth0.com/docs/flows/authorization-code-flow (example) https://next-auth.js.org/configuration/callbacks#jwt-callback |
Hi, Thanks already, getting the token in the No that's still a big flaw, Azure AD B2C is being used. Thanks! |
https://docs.microsoft.com/en-us/azure/active-directory-b2c/authorization-code-flow#2-get-an-access-token You should be able to configure it with a custom provider's accesstoken url https://next-auth.js.org/configuration/providers#using-a-custom-provider Keep an eye on #809 ;) |
Great to hear that this'll be a built-in provider! 👏 At the moment my custom provider works like a charm, except getting the accessToken doesn't seem to work yet.
I'll go over the steps again , probably missed something. Provider:
|
You can try adding If you are comfortable with the OAUTH spec, you can try re-playing the steps of an authentication from Postman, and see that the access_token actually gets sent where it needs to be, or is it a configuration issue in your Azure setup. If that is the case, the error is not in |
Jep the debug is very helpful, I'm not getting the accessToken back at all from azure. |
You mention fetching the token in the jwt() callback. How do I deal with errors in this callback? |
Your question
Unable to set accessToken in signIn callback
What are you trying to do
I'm trying to add an accessToken to the session object coming from a custom backend.
When the user signs in we fetch an accessToken from a custom backend in the
signIn callback
.Still in the
signIn callback
we set the accessToken on the useruser.accessToken = data.authToken
.In the
jwt callback
we check for a user, if present we add the accessToken from the user - at this stage we do not have the fetched accessToken anymore as a result we can't access it in the session either.Feedback
I followed the referred to example but to no avail. Is it possible the referred to document is outdated and this is no longer possible? Staring at it for quite a while, am I missing something obvious? Thanks in advance!
The text was updated successfully, but these errors were encountered: