Java getName()返回facebook的ID而不是名称
我使用SpringSecurityOAuth实现了我的自定义身份验证服务器,以及几个用于单点登录的客户端应用程序,我可以选择facebook和google登录 现在,在我的客户端应用程序上,当我拥有此控制器时:Java getName()返回facebook的ID而不是名称,java,facebook-graph-api,spring-boot,single-sign-on,spring-security-oauth2,Java,Facebook Graph Api,Spring Boot,Single Sign On,Spring Security Oauth2,我使用SpringSecurityOAuth实现了我的自定义身份验证服务器,以及几个用于单点登录的客户端应用程序,我可以选择facebook和google登录 现在,在我的客户端应用程序上,当我拥有此控制器时: @RequestMapping({ "/user", "/me" }) public Principal user(Principal principal) { return principal; } 对于谷歌来说,它工作正常并返回名称,但对于facebook,它返回一
@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
使用
f_name
而不是name
用于Facebook图形API使用f_name
而不是name
用于Facebook图形API好的,我找到了解决方法:
@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;
}
@RequestMapping(值={/user“,“/me”},方法=RequestMethod.GET)
公共地图用户(主体){
映射详细信息=(映射)((OAuth2Authentication)主体).getUserAuthentication().getDetails();
Map Map=newlinkedhashmap();
map.put(“name”,(String)details.get(“name”);
map.put(“email”),(String)details.get(“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;
}
@RequestMapping(值={/user“,“/me”},方法=RequestMethod.GET)
公共地图用户(主体){
映射详细信息=(映射)((OAuth2Authentication)主体).getUserAuthentication().getDetails();
Map Map=newlinkedhashmap();
map.put(“name”,(String)details.get(“name”);
map.put(“email”),(String)details.get(“email”);
返回图;
}