package com.sso.demo.controller; import cn.hutool.core.collection.CollectionUtil; import org.springframework.beans.factory.annotation.Value; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.client.RestTemplate; import sun.misc.BASE64Encoder; import java.io.UnsupportedEncodingException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; /** * @author zlt * @date 2020/3/10 *
* Blog: https://zlt2000.gitee.io
* Github: https://github.com/zlt2000
*/
@RestController
public class ApiController {
@Value("${zlt.sso.client-id:}")
private String clientId;
@Value("${zlt.sso.client-secret:}")
private String clientSecret;
@Value("${zlt.sso.redirect-uri:}")
private String redirectUri;
@Value("${zlt.sso.access-token-uri:}")
private String accessTokenUri;
@Value("${zlt.sso.user-info-uri:}")
private String userInfoUri;
@GetMapping("/token/{code}")
public Map tokenInfo(@PathVariable String code) throws UnsupportedEncodingException {
//获取token
Map tokenMap = getAccessToken(code);
String accessToken = (String)tokenMap.get("access_token");
//获取用户信息
Map userMap = getUserInfo(accessToken);
List