-
Notifications
You must be signed in to change notification settings - Fork 6.1k
Support refreshing OIDC ID Token #16253
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
Comments
Related gh-15509 |
Hi @filiphr. I wanted to get your thoughts on PR #16589. Specifically, I wonder if you feel that it has the potential to help with this issue? The reason I ask is that with that PR, we would be publishing an event with the full By contrast, I am not sure whether Spring Security should support this issue directly. The reason I feel that way is that the framework does not have any use of an ID token outside of authentication, and the use of ID tokens for non-authentication purposes (at the client) are not defined in any specs I'm aware of. For example, you mentioned Google's use of ID tokens but I don't know of any specifications that govern those use cases. Are you aware of any related specs? If I'm correct that Google's uses are off-spec, I think it's fairly reasonable to build a custom solution such as yours. However, it could be made much nicer with the enhancement from #16589, which seems a decent tradeoff. What do you think? |
Thanks for checking @sjohnr. The PR #16589 is a good one, especially when needing to access the current login registration. However, I am not sure that it is enough, it only does a refresh when the access token has expired, so if the access token has a longer expiration time than the ID Token, then the PR will not help. My main problem is that when using something like For my particular use case I think that it would be more than enough if the Perhaps we can change the issue to something like "Expose OAuth2AccessTokenResponse additionalParameters to OAuth2AuthorizedClient` |
@filiphr, thanks. I hear what you're saying and it makes sense.
If the ID token was part of the
Ok. Let's leave this open and see if we get some upvotes from others needing something similar.
We certainly could. I do think the title is accurate for what you're really after though. So in the interest of others finding it and upvoting it, I'm inclined to leave it as is. |
Expected Behavior
When using the
@RegisteredOAuth2AuthorizedClient
orOAuth2AuthorizedClient
I would like to use the OIDC ID Token instead of the Access Token.I would like to use the existing functionality around
OAuth2AuthorizedClient
andOAuth2AuthorizedClientRepository
to leverage the persistence of the refresh token and theRefreshTokenOAuth2AuthorizedClientProvider
which offers the functionality for refreshing a token.Current Behavior
Currently, when using the
@RegisteredOAuth2AuthorizedClient
andOAuth2AuthorizedClient
, we only have access to the Access Token and we can only refresh that one.Context
We have our own applications, for which we support different OIDC providers thanks to Spring Security. There are some use cases for us where one of the applications is proxying requests to some of the other applications, and in this case the ID Token should be used when communicating over REST.
There are certain APIs that required the usage of the ID Token when communicating over REST instead of the Access Token.
E.g. According to the Google Get an ID token a Google-signed ID token is needed for the following use cases:
Currently, we implemented a really ugly solution fully inspired by the
OAuth2AuthorizedClientRepository
,DefaultOAuth2AuthorizedClientManager
andRefreshTokenOAuth2AuthorizedClientProvider
.We first get the OIDC ID Token from the current
OidcUser
and / or from a repository like theOAuth2AuthorizedClientRepository
.If the token is expired, we then use
OAuth2AuthorizedClientRepository
to get theOAuth2AuthorizedClient
, then we get the refresh token and we do exactly what is being done inRefreshTokenOAuth2AuthorizedClientProvider
, the refreshed ID Token is inid_token
in the additional parameters inOAuth2AccessTokenResponse
.Once we get the refreshed ID Token, we store it in something similar like the
OAuth2AuthorizedClientRepository
I think that it would be good if this was coming natively from Spring Security. If you are open to something like this I would be open in working on a contribution for this.
My current idea is to add an
OidcIdToken
in theOAuth2AuthorizedClient
, expandRefreshTokenOAuth2AuthorizedClientProvider
to allow to use a custom attribute in theOAuth2AuthorizationContext
to determine which token we want to use (in order to check for the validity and do the refresh). This class will be responsible for parsing theid_token
from the additional parameters from theOAuth2AuthorizationContext
.Of course, we need to review the other
OAuth2AuthorizedClientProvider
(s) to see which places might return an ID Token in addition to an access token.The text was updated successfully, but these errors were encountered: