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
Add support for nested property names in oauth2.providers.userNameAttribute #14186
Comments
Hi, @leeavital, thanks for the suggestion. I think this sounds reasonable. I believe three steps are needed to make this work. First, public DefaultOAuth2User(Map<String, Object> attributes, Collection<? extends GrantedAuthority> authorities, String name) Second, Spring Security should update existing production code (not tests) to use the new constructor. Third, SimpleEvaluationContext context = SimpleEvaluationContext
.forPropertyAccessors(new MapAccessor())
.withRootObject(userAttributes).build();
SpelExpressionParser parser = new SpelExpressionParser();
Expression expression = parser.parseExpression(userNameAttributeName);
String name = (String) expression.getValue(context);
return new DefaultOAuth2User(userAttributes, authorities, name); Would you be interested in submitting a PR to make these changes? If not, I can make the changes instead and invite you to review the PR. |
If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed. |
@jzheaux I think I can do that. is it ok if I work on it ? |
Sounds good, @ahmd-nabil |
Closes spring-projectsgh-14186 Signed-off-by: ahmd-nabil <ahm3dnabil99@gmail.com>
Polish Custom Username Location
Closes spring-projectsgh-14186 Signed-off-by: ahmd-nabil <ahm3dnabil99@gmail.com>
Closes spring-projectsgh-14186 Signed-off-by: ahmd-nabil <ahm3dnabil99@gmail.com>
Closes spring-projectsgh-14186 Signed-off-by: ahmd-nabil <ahm3dnabil99@gmail.com>
Closing in favor of #14265 |
- Add Tests - Add Reactive Support Issue spring-projectsgh-14186
Closes gh-14186 Signed-off-by: ahmd-nabil <ahm3dnabil99@gmail.com>
- Add Tests - Add Reactive Support Issue gh-14186
Hello, When adding a breakpoint in IntelliJ, I discovered, that the returned object for my userinfo is a LinkedHashMap containing more LinkedHashMaps, so the returned data by the server is correct. I don't know if this issue covered 1: This is what the data looks like: {
"data": {
"email": "users email address",
"more": "data"
},
"meta": {
"other": "data"
}
} |
Ok, sorry for this, I didn't realise that this wasn't included in the Spring Boot Starter release. Here is a working example with this PR. |
Expected Behavior
I was trying to configure my app to use the pagerduty oauth2 provider, I was using the following configuration:
The pagerduty
/me
api returns users with all the interesting properties nested under theuser
field, like so:I tried setting
userNameAttribute: user.email
expecting the name field to be extracted as thename
property on theuser
object. But I get an error from DefaultOAuth2User:"Missing attribute 'user.email' in attributes
.Current Behavior
Ideally a user would successfully be extracted, and login would be successful.
Context
I wound up exposing a custom OAuth2UserService class, but it's 90% of a copy paste of
DefaultOAuth2UserService
, and this seems like something that another user info API might reasonably do.The text was updated successfully, but these errors were encountered: