|
@@ -138,4 +138,45 @@ public class SysLoginController {
|
|
|
return ajax;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 登录方法
|
|
|
+ *
|
|
|
+ * @param loginBody 登录信息
|
|
|
+ * @return 结果
|
|
|
+ */
|
|
|
+ @PostMapping("/getAzureAccessToken")
|
|
|
+ public AjaxResult getAzureAccessToken(@RequestBody LoginBody loginBody) {
|
|
|
+ AjaxResult ajax = AjaxResult.success();
|
|
|
+ // 生成令牌
|
|
|
+ String code = loginBody.getCode();
|
|
|
+
|
|
|
+ // 1.1 构建请求头
|
|
|
+ HttpHeaders headers = new HttpHeaders();
|
|
|
+ headers.setContentType(MediaType.APPLICATION_JSON);
|
|
|
+ headers.add("Authorization", "Bearer ");
|
|
|
+ // 1.2 构建请求参数
|
|
|
+ Map<String, String> body = new HashMap<>();
|
|
|
+ body.put("code", code);
|
|
|
+ body.put("grant_type", "authorization_code");
|
|
|
+ body.put("client_secret", "FdR8Q~hmMJsJtJzPhDntTMwRv2WKD6dEhpSKraqk");
|
|
|
+ body.put("client_id", "3db6f125-db4d-456b-a76e-a6d03182e845");
|
|
|
+ body.put("redirect_uri", "http://localhost/cpms/index.html#/azureLogin");
|
|
|
+ // 2. 执行请求
|
|
|
+ ResponseEntity<AjaxResult> exchange = restTemplate.exchange(
|
|
|
+ "https://login.microsoftonline.com/7503e40a-97ec-4eb9-bf6d-2836e57e882d/oauth2/v2.0/token",
|
|
|
+ HttpMethod.POST,
|
|
|
+ new HttpEntity<>(body, headers),
|
|
|
+ new ParameterizedTypeReference<AjaxResult>() {
|
|
|
+ }); // 解决 CommonResult 的泛型丢失
|
|
|
+ Assert.isTrue(exchange.getStatusCode().is2xxSuccessful(), "响应必须是 200 成功");
|
|
|
+ ajax = exchange.getBody();
|
|
|
+ System.out.println(ajax.toString());
|
|
|
+ ajax.get("access_token");
|
|
|
+ //进行jwt解析
|
|
|
+
|
|
|
+ //系统登录 获取系统token
|
|
|
+
|
|
|
+ return ajax;
|
|
|
+ }
|
|
|
+
|
|
|
}
|