Search code examples
spring-security-oauth2jose4j

Intermixing Spring Security OAuth2 and Jose4j


I was wondering (before I try implemnting somethign along this path) about an approach. Lets say I have a complete working OAuth2 system (using spring boot and spring cloud but not spring cloud security). This, so far has worked quite well and supports several different grant types. What I am interested in is the possibility of hand creating the JWT in certain special cases and then utilizing this token with spring security. I looked at jose4j and it seems like i should be able to use this in place of the authorization server portion of the system. Note that the goal of this was where i had to create a token that would have normally be generated by the authorization server.


Solution

  • You might want to look at TokenEnhancer or in particular JwtAccessTokenConverter. The latter one also provides encode/decode methods you can overwrite to use custom libraries for encoding/decoding of tokens or to add custom properties.

    Note: Make sure to check the signature of the tokens!