|
@@ -1,14 +1,13 @@
|
|
|
package com.ruoyi.project.system.controller;
|
|
|
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.Set;
|
|
|
+import java.util.*;
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.core.ParameterizedTypeReference;
|
|
|
import org.springframework.http.*;
|
|
|
import org.springframework.util.Assert;
|
|
|
+import org.springframework.util.LinkedMultiValueMap;
|
|
|
+import org.springframework.util.MultiValueMap;
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
@@ -154,20 +153,23 @@ public class SysLoginController {
|
|
|
HttpHeaders headers = new HttpHeaders();
|
|
|
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
|
|
|
headers.add("Authorization", "Bearer ");
|
|
|
+
|
|
|
// 1.2 构建请求参数
|
|
|
- Map<String, String> body = new HashMap<>();
|
|
|
- body.put("code", code);
|
|
|
- body.put("grant_type", "authoization_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");
|
|
|
+ MultiValueMap<String, String> body = new LinkedMultiValueMap<>();
|
|
|
+ body.put("code", new LinkedList<String>(){{ add(code); }});
|
|
|
+ body.put("grant_type", new LinkedList<String>(){{ add("authorization_code"); }});
|
|
|
+ body.put("client_secret", new LinkedList<String>(){{ add("FdR8Q~hmMJsJtJzPhDntTMwRv2WKD6dEhpSKraqk"); }});
|
|
|
+ body.put("client_id", new LinkedList<String>(){{ add("3db6f125-db4d-456b-a76e-a6d03182e845"); }});
|
|
|
+ body.put("redirect_uri", new LinkedList<String>(){{ add("http://localhost/cpms/index.html"); }});
|
|
|
+ body.put("scope", new LinkedList<String>(){{ add("api://3db6f125-db4d-456b-a76e-a6d03182e845/User.Read"); }});
|
|
|
+
|
|
|
// 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 的泛型丢失
|
|
|
+ new ParameterizedTypeReference<AjaxResult>() {}); // 解决 CommonResult 的泛型丢失
|
|
|
+
|
|
|
Assert.isTrue(exchange.getStatusCode().is2xxSuccessful(), "响应必须是 200 成功");
|
|
|
ajax = exchange.getBody();
|
|
|
System.out.println(ajax.toString());
|