Reputation: 930
How can I get details from the OAuth2 SSO Principal
into my JWT? (instance of OAuth2Authentication
getDetails
as OAuth2AuthenticationDetails
getDecodedDetails
returns null
)
I have...
acme
client (using angular-oauth2-oidc
)Spring Boot OAuth2 Authorization Server with JWT TokenService
configuration w/ 3rd party SSO to GitHub
Auth server is configured with acme
as implicit
and GitHub client for SSO
/login/github
/me
(protected by ResourceServer config)When I login...
Now, when I communicate with Auth Service /me
:
Principal
that contains ALL of the details from GitHub (yay)Authorization: Bearer ...
header, I get a Principal
that contains bare minimum OAuth client info for acme
client (ugh)I've tried a custom TokenEnhancer
, but the OAuth2Authentication
instance is already the bare minimum with no details. And, when the call is initiated from Angular, it doesn't have the same session cookie as when I call it directly (I don't want to share session - I want to put the details in the JWT).
[Update #1]
I tried a custom JwtAccessTokenConverter
and used it in both of the @EnableAuthorizationServer
and @EnableResourceServer
(secures the /me
endpoint) configuration classes. However it didn't work. I still get null details from OAuth2Authentication
.
final JwtAccessTokenConverter converter = new JwtAccessTokenConverter();
converter.setAccessTokenConverter(new CustomTokenConverter());
Upvotes: 0
Views: 473
Reputation: 8965
The way Spring Lemon does this is replacing the OAuth2 and OpenID connect user services (see spring security docs). See LemonOAuth2UserService
and LemonOidcUserService
for details. For statelessness, it passes the client a shortlived JWT token as a param to targetUrl, as you can see in its OAuth2AuthenticationSuccessHandler
class. It uses some cookies mechanism for doing all this statelessly, which can be further understood by looking at its HttpCookieOAuth2AuthorizationRequestRepository
and how it's configured.
Here is an article explaining this in more details: https://www.naturalprogrammer.com/blog/1681261/spring-security-5-oauth2-login-signup-stateless-restful-web-services .
Upvotes: 0