spring-projects / spring-security

Spring Security
http://spring.io/projects/spring-security
Apache License 2.0
8.48k stars 5.77k forks source link

Expose user name attribute name in `OAuth2UserAuthority` #15012

Open filiphr opened 3 weeks ago

filiphr commented 3 weeks ago

We are using custom GrantedAuthoritiesMapper that is doing some custom loading of attributes based on the OAuth2UserAuthority. We've had some request to do something based on the user name. Currently, there is no easy way to access the configured username attribute name.

The goal of this PR is to expose this information directly in the OAuth2UserAuthority and this make it easy to get the username from the attributes.

An alternative could also be to expose getUserName and just use the userNameAttributeName in the OAuth2UserAuthority.

I hope that you'll consider this PR, if there is anything that you think should be added or done better please let me know

filiphr commented 4 days ago

Can someone from the Spring Security team have a look at this? If this is something that you are not interested in then let me know and we can close it.

sjohnr commented 2 days ago

Thanks @filiphr! I'll be taking a look at this and send any feedback in the next few days. Overall it seems reasonable and a nice enhancement so I think we should be able to accept it.