【发布时间】:2019-11-01 05:33:05
【问题描述】:
我编写了 oauth2 社交客户端,但无法获取授权用户的好友列表 请查看我的代码以查看缺少的内容/ 问候
请看@RequestMapping("vkontakte/friends")
java 1.8 春季安全
@SpringBootApplication
@RestController
@EnableOAuth2Client
public class SocialApplication extends WebSecurityConfigurerAdapter {
@Autowired
OAuth2ClientContext oAuth2ClientContext;
@RequestMapping({ "/user", "/me" })
public Map<String, String> user(Principal principal) {
Map<String, String> map = new LinkedHashMap<>();
map.put("name", principal.getName());
return map;
}
//TODO как это оформить на фронтенде?
@RequestMapping("/vkontakte/friends")
public Map<String,String> friends() {
OAuth2RestTemplate vkTemplate = new OAuth2RestTemplate(vk(), oAuth2ClientContext);
UserInfoTokenServices tokenServicesvk = new UserInfoTokenServices(vkResource().getUserInfoUri(), vk().getClientId());
tokenServicesvk.setRestTemplate(vkTemplate);
ObjectNode resultNode = vkTemplate.getForObject(vkResource().getUserFriendsInfoUri(), ObjectNode.class);
ArrayNode data = (ArrayNode) resultNode.get("data");
Map<String, String> map = new LinkedHashMap<>();
for (JsonNode dataNode : data) {
//TODO надо как то правильно все получить?
}
return map;
【问题讨论】:
标签: java spring security oauth-2.0