Skip to content
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

How to enrich Principal on resource server side #170

Open
HJK181 opened this issue Dec 5, 2017 · 1 comment
Open

How to enrich Principal on resource server side #170

HJK181 opened this issue Dec 5, 2017 · 1 comment

Comments

@HJK181
Copy link

HJK181 commented Dec 5, 2017

Hi Dave,

i'm trying to implement a setup similar to the oauth2-logout sample. My setup uses a zuul server as SSOClient, an oauth2 server and a resources server. I wonder how can I enrich the principal information on the resoruces server side?

I have the following code:

@RequestMapping("/me")
	@ResponseBody
	public Principal getCurrentLoggedInUser(Principal user) {
		return user;
	}

Where I need more informations from my domain user model. I've tried to write a custom TokenEnhencer:

@Override
	public OAuth2AccessToken enhance(OAuth2AccessToken accessToken, OAuth2Authentication authentication) {

		final TenantUser user = (TenantUser) authentication.getPrincipal();
		final Map<String, Object> additionalInfo = new HashMap<>();

		additionalInfo.put("gender", user.getUser().getGender());

		((DefaultOAuth2AccessToken) accessToken).setAdditionalInformation(additionalInfo);

		return accessToken;
	}

But the "gender" information is not present on my Principal object.
Its only present when I use the /token endpoint to grand a new access_token.

I'm sure that I'm mixing up something. Could you please give me a hint how the enrich data transported by JWT so that the ressources server can extract it from the current user?

Thank you.

@dsyer
Copy link
Collaborator

dsyer commented Feb 12, 2018

I'm not sure I follow. If the token does not contain the information you need in the resource server, I don't think it has any choice but to extract it from somewhere else (like a database, or am HTTP endpoint or something). It's nothing to do with tokens or JWTs at that point.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants