-
Notifications
You must be signed in to change notification settings - Fork 4k
Description
Summary of proposed feature
Acces id_token in jwt callback, when idToken: true in a provider's option.
Purpose of proposed feature
Make it possible to start a logout process from a next app using next-auth that will log out from the Identity Provider entirely, if it is OIDC compliant.
Detail about proposed feature
OpenID Connect compliant IdPs (like IdentiyServer4, which is also supported by next-auth) have a federated logout.
To initiate such a logout process, when signOut() is called, next-auth should redirect to https://idp.com/endsession, and forward at least the two following query params:
id_token_hint: The originalid_tokenreceived from the IdP at login.post_logout_redirect_uri: A preconfigured URL in the IdP client, that the IdP should redirect to after a successful logout. This could default toNEXTAUTH_URL, but could be overridden in a provider setting. (Note that the same url must be registered in the IdP client)
Additional optional query params exist, see the relevant spec section
Obtaining the id_token at the initial jwt() callback call would make it possible to preserve it in a session database, or in the jwt token itself.
Potential problems
-
According to the JWT callback docs
jwtcallback has already many parameters, and adding a newidTokenwould just make it worse. In my opinion should/could be provided as a single object to basically be able to use named params, but that would be a breaking change. -
Setting the
id_tokenin the JWT cookie is kind of an overhead, as the cookie most possibly contains some kind of a mapping of the id_token (name, email, etc.) already. My solution for this would be to not store it in the cookie, but create an in-memory database (just a JS class with key value pairs, where keys are user ids, and each user contains a list of sessions, containing sessions'id_tokens. Hint: The id_token usually contains asidor Session ID, and timestamps if needed). Adding such an in-memory database should not be required from most of the users though. (Although this could very well be an optional part ofnext-auth, that could also complement RFC: Limit logins (by concurrency, location) #583 nicely, which I am already working on at work, and some day be able to share it as a PR tonext-auth) I am open for suggestions here! -
There is the 4096 bytes cookie size limit in browser, and because of that every extra bytes count, if we cannot somehow divide the data into multiple cookies somehow. (I am no expert on cookies though, so I do not know hard it would be to split/merge cookies)
Describe any alternatives you've considered
I haven't considered alternatives to next-auth as it is generally a high quality full auth solution for Next.js apps, and since it already supports idToken for OIDC compliant IdPs, it would only make sense to leverage that even further.
Additional context
OIDC spec: https://openid.net/specs/openid-connect-rpinitiated-1_0.html
Relevant IDS4 documentation: https://identityserver4.readthedocs.io/en/latest/endpoints/endsession.html
id_token content: https://docs.microsoft.com/en-us/azure/active-directory/develop/id-tokens#payload-claims
Please indicate if you are willing and able to help implement the proposed feature.
If this is not a problem that can be solved in user land right now, I may be willing to try to implement this and open a PR for it, but before that, I need feedback on how to store the id_token in the jwt callback, with minimal overhead.
So just a TLDR:
If the user provides the idToken: true option as a Provider option, it would be nice to send it as a param to the jwt callback as well. The rest can strictly speaking be implemented by the user for now.