princiapal.getName() 返回 ID 而不是 Facebook 的名称



我使用spring-security-oauth以及几个用于单点登录的客户端应用程序实现了我的自定义身份验证服务器,我可以选择Facebook和Google登录。

现在在我的客户端应用程序上,当我有这个控制器时:

    @RequestMapping({ "/user", "/me" })
public Principal user(Principal principal) {
    return principal;
}
对于

谷歌,它工作正常并返回名称,但对于Facebook,它返回一个唯一的ID。我已经尝试了很多方法,但我无法从这个主要对象中获取名称。有人可以帮忙吗?

这是我的快捷方式Facebook配置:

accessTokenUri: https://graph.facebook.com/oauth/access_token
userAuthorizationUri: https://www.facebook.com/dialog/oauth
tokenName: oauth_token
authenticationScheme: query
clientAuthenticationScheme: form
userInfoUri: https://graph.facebook.com/me?fields=id,name,email
好的,

我得到了解决方法:

    @RequestMapping(value = { "/user", "/me"}, method = RequestMethod.GET)
public Map<String, String> user(Principal principal) {
    Map<String, Object> details = (Map<String, Object>) ((OAuth2Authentication) principal).getUserAuthentication().getDetails();
    Map<String, String> map = new LinkedHashMap<>();
    map.put("name", (String) details.get("name"));
    map.put("email", (String) details.get("email"));
    return map;
}

Facebook Graph API 使用 f_name 而不是 name

最新更新