-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
feat: Forward idToken to callbacks #837
Conversation
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/nextauthjs/next-auth/q93uvnpwq |
@iaincollins Not sure if I should update the docs here as well:
Can |
@@ -25,7 +25,7 @@ You can specify a handler for any of the callbacks below. | |||
session: async (session, user) => { | |||
return Promise.resolve(session) | |||
}, | |||
jwt: async (token, user, account, profile, isNewUser) => { | |||
jwt: async (token, user, account, profile, isNewUser, idToken) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@iaincollins This (and probably any other public-facing function signature using more than 2 params) should at some point (maybe v4) become an object to leverage named parameters It is much easier for the user to pick only those params that they are going to use.
Can we get this merged? Happy to help if I can but desperate to use this on a project. Cheers! :) |
@ryangittings hope to get this merged soon. As it's a user facing change, I would like to review it with someone else from the core team before merge. (will have a chat with @iaincollins tomorrow, so hopefully then 🤞) |
Continued at #1024 |
🎉 This issue has been resolved in version 3.2.0-canary.10 🎉 The release is available on: Your semantic-release bot 📦🚀 |
🎉 This issue has been resolved in version 3.3.0-canary.1 🎉 The release is available on: Your semantic-release bot 📦🚀 |
This is a bare minimum change required so an OpenID Connect compliant Identity Provider, (like IdentityServer4) can initiate a logout process from the IdP from within an app using
next-auth
, and return to the application afterwards.According to the spec, an
id_token
must be present as either a query param (in case ofGET
) or as a body in case ofPOST
tohttps://IdP.com/connect/endsession
to be able to redirect back to the application (or anywhere else explicitely allowed so in the IdP client bypost_logout_redirect_uri
) after a successful logout.This change forwards the
id_token
as-is tocallbacks.signIn
andcallbacks.jwt
initially, and leaves it up to the user to store that as they want to (probably either in a session database or in the JWT token).There may be other situations where access to the
id_token
in that manner might be useful.Related issues: #836, closes #393, closes #378
UPDATE:
I decided that in case an
id_token
is present, it should always be sent to the callbacks, regardless ofidToken: true
is set, or not.The reasoning is that I thought that by setting
idToken: true
, I could skip an extra request to the/userinfo
IdP endpoint. The problem is, that if I useid_token
, all the claims must be sent from the IdP, making theid_token
too big to send it again while using the/connect/endsession
endpoint, destroying the purpose of this PR.So here is a rough breakdown of how this PR solves my problem.
/api
endpoint in Next.js, call it/api/auth/federated-logout
With the provided
id_token_hint
to/connect/endsession
will be able log the user out without consent, and redirect back tohttp://localhost:3000?forceLogout=true
In
_app
add the following:<a href="/api/auth/federated-logout">Log out everywhere</a>
link somewhere in the app.