Skip to content

Add constructor to JwtAuthenticationToken that takes principal #7834

@xak2000

Description

@xak2000

Currently, JwtAuthenticationToken always pass one Jwt instance to super constructor (AbstractOAuth2TokenAuthenticationToken) as token, principal and credentials. So, that implies that all three values must always be a jwt token itself.

I don't see any reason why principal in JWT token must always be the token itself. It already represents both token and credentials. But for principal I want more flexibility: an ability to also load user (represented by JWT "sub" claim) from DB or external service.

In my application I want to use a JWT token, but I also want to create a custom class that will represent a principal, like UserDetials implementation or just a new custom class.

AbstractOAuth2TokenAuthenticationToken has a constructor, that takes token, principal and credentials separately.

It would be good, if JwtAuthenticationToken also have a constructor, that at least takes principal separately.

If this will be added, then it will also be good if JwtAuthenticationConverter will have an optional property

Converter<Jwt, Object> jwtPrincipalConverter;

which, if set, will be used to convert Jwt to principal (by loading it from DB, external service, or just by creating a more application-friendly User object from Jwt token) before calling new JwtAuthenticationToken constructor.

Metadata

Metadata

Assignees

Labels

in: oauth2An issue in OAuth2 modules (oauth2-core, oauth2-client, oauth2-resource-server, oauth2-jose)status: invalidAn issue that we don't feel is valid

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions