You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, the DefaultOAuth2UserService seems to expect the userNameAttributeName configured in the ClientRegistration to be a top-level attribute in the JSON response from the UserInfo endpoint. However, some OAuth2 providers return user information nested within a structured object (e.g., under a data key).
In this case, the desired unique identifier for the user might be open_id, which is located at data.open_id.
Expected Behavior
It should be possible to configure the userNameAttributeName to specify a path to a nested attribute. For instance, configuring userNameAttributeName as data.open_id (using dot notation or a similar standard like JSON Pointer /data/open_id) should instruct the OAuth2UserService to extract the value "ou-caecc734c2e3328a62489fe0648c4b98779515d3" from the example JSON and use it as the principal name (i.e., the value returned by OAuth2User.getName()).
Current Behavior
Based on the code in DefaultOAuth2UserService (and how DefaultOAuth2User uses the userNameAttributeName), it appears the framework expects userNameAttributeName to be a direct key in the top-level userAttributes map.
Trying to set userNameAttributeName to data.open_id likely results in the principal name being null or an error, because there is no top-level key named "data.open_id" in the userAttributes map. The framework does not seem to parse nested paths for this attribute.
Context
How has this issue affected you? This limitation prevents straightforward integration with OAuth2 providers whose UserInfo endpoints return essential user identifiers within nested JSON objects. We are trying to integrate with a provider (like Feishu/Lark) that uses this nested structure.
What are you trying to accomplish? We need to reliably extract the open_id from the nested data object in the UserInfo response and use it as the primary user identifier within our Spring Security context.
What other alternatives have you considered?
Implementing a custom OAuth2UserService to manually parse the response and extract the nested attribute. This works but adds boilerplate code for a relatively common scenario.
Are you aware of any workarounds? The primary workaround is creating a custom OAuth2UserService, as mentioned above. However, native support in the framework would be cleaner and more convenient.
Suggestion:
Consider enhancing the DefaultOAuth2UserService (or related components) to support a path expression (e.g., dot notation data.open_id or JSON Pointer /data/open_id) for the userNameAttributeName configuration, allowing developers to easily specify nested attributes as the user identifier.
The text was updated successfully, but these errors were encountered:
Issue Description:
Currently, the
DefaultOAuth2UserService
seems to expect theuserNameAttributeName
configured in theClientRegistration
to be a top-level attribute in the JSON response from the UserInfo endpoint. However, some OAuth2 providers return user information nested within a structured object (e.g., under adata
key).Example UserInfo Response:
Some providers, like Feishu/Lark, return a UserInfo response structured like this (https://open.feishu.cn/document/server-docs/authentication-management/login-state-management/get):
In this case, the desired unique identifier for the user might be
open_id
, which is located atdata.open_id
.Expected Behavior
It should be possible to configure the
userNameAttributeName
to specify a path to a nested attribute. For instance, configuringuserNameAttributeName
asdata.open_id
(using dot notation or a similar standard like JSON Pointer/data/open_id
) should instruct theOAuth2UserService
to extract the value"ou-caecc734c2e3328a62489fe0648c4b98779515d3"
from the example JSON and use it as the principal name (i.e., the value returned byOAuth2User.getName()
).Current Behavior
Based on the code in
DefaultOAuth2UserService
(and howDefaultOAuth2User
uses theuserNameAttributeName
), it appears the framework expectsuserNameAttributeName
to be a direct key in the top-leveluserAttributes
map.Trying to set
userNameAttributeName
todata.open_id
likely results in the principal name beingnull
or an error, because there is no top-level key named"data.open_id"
in theuserAttributes
map. The framework does not seem to parse nested paths for this attribute.Context
open_id
from the nesteddata
object in the UserInfo response and use it as the primary user identifier within our Spring Security context.OAuth2UserService
to manually parse the response and extract the nested attribute. This works but adds boilerplate code for a relatively common scenario.OAuth2UserService
, as mentioned above. However, native support in the framework would be cleaner and more convenient.Suggestion:
Consider enhancing the
DefaultOAuth2UserService
(or related components) to support a path expression (e.g., dot notationdata.open_id
or JSON Pointer/data/open_id
) for theuserNameAttributeName
configuration, allowing developers to easily specify nested attributes as the user identifier.The text was updated successfully, but these errors were encountered: