oauth2-bundle icon indicating copy to clipboard operation
oauth2-bundle copied to clipboard

Is there an easy way to add custom data to the JWT payloads?

Open pkly opened this issue 4 years ago • 2 comments

As far as I can see there's no easy way to modify the payloads for AuthCode and AccessToken/RefreshToken.

It'd be nice if there would be an event about the user being used in the request along with the entities free to modify, the custom data could just be stored as json in the entity itself.

As of now I'm simply creating an additonal entity, linking it to the AccessToken entity (or AuthCode entity), and making my own AccessTokenRepository or AuthCodeRepository where I modify some functions. (btw shame those classes are final)

pkly avatar Aug 17 '20 06:08 pkly

Hey, I've looked for a way to implement that with an event since my current PR is about that.

Unfortunately, when adding custom value those didn't appear in the JWT payload.

By doing further investigation I find out that it was not supported in thephpleague/oauth2-server and apparently they didn't want to support it, to avoid having heavy payload and other ...

I just did a quick search over it, maybe they now allow it, in that case tell me and i'll try to add to my PR or in a future one ;-)

froozeify avatar Dec 14 '20 09:12 froozeify

@pkly You could extend the "BearerTokenResponse" of the League Bundle and override the "getExtraParams()" Method. See the Comment of the Method.

This Bundle here (Thanks to Steve Rhoades) uses this Method to inject an open ID Token to the Response.

DevNiko avatar Jan 29 '21 11:01 DevNiko