Commit bf700ab1fc79d23b882533981517217e70ef627e

Authored by YunaiV
1 parent 05951783

增加 yudao-sso-demo-by-password 示例,基于密码模式,实现 SSO 单点登录

yudao-example/yudao-sso-demo-by-password/src/main/java/cn/iocoder/yudao/ssodemo/client/OAuth2Client.java
@@ -31,7 +31,7 @@ public class OAuth2Client { @@ -31,7 +31,7 @@ public class OAuth2Client {
31 */ 31 */
32 public static final Long TENANT_ID = 1L; 32 public static final Long TENANT_ID = 1L;
33 33
34 - private static final String CLIENT_ID = "yudao-sso-demo-by-code"; 34 + private static final String CLIENT_ID = "yudao-sso-demo-by-password";
35 private static final String CLIENT_SECRET = "test"; 35 private static final String CLIENT_SECRET = "test";
36 36
37 37
yudao-example/yudao-sso-demo-by-password/src/main/resources/static/login.html
@@ -13,31 +13,31 @@ @@ -13,31 +13,31 @@
13 */ 13 */
14 function login() { 14 function login() {
15 const clientId = 'yudao-sso-demo-by-password'; // 可以改写成,你的 clientId 15 const clientId = 'yudao-sso-demo-by-password'; // 可以改写成,你的 clientId
16 - const clientSecret = 'test'; // 可以改写成,你的 clientSecret  
17 - const grantType = 'password'; // 密码模式 16 + const clientSecret = 'test'; // 可以改写成,你的 clientSecret
  17 + const grantType = 'password'; // 密码模式
18 18
19 - // 账号 + 密码  
20 - const username = $('#username').val();  
21 - const password = $('#password').val(); 19 + // 账号 + 密码
  20 + const username = $('#username').val();
  21 + const password = $('#password').val();
22 if (username.length === 0 || password.length === 0) { 22 if (username.length === 0 || password.length === 0) {
23 alert('账号或密码未输入'); 23 alert('账号或密码未输入');
24 return; 24 return;
25 - } 25 + }
26 26
27 // 发起请求 27 // 发起请求
28 $.ajax({ 28 $.ajax({
29 url: "http://127.0.0.1:48080/admin-api/system/oauth2/token?" 29 url: "http://127.0.0.1:48080/admin-api/system/oauth2/token?"
30 // 客户端 30 // 客户端
31 - + "client_id=" + clientId 31 + + "client_id=" + clientId
32 + "&client_secret=" + clientSecret 32 + "&client_secret=" + clientSecret
33 - // 密码模式的参数  
34 - + "&grant_type=" + grantType  
35 - + "&username=" + username  
36 - + "&password=" + password  
37 - + '&scope=user.read user.write', 33 + // 密码模式的参数
  34 + + "&grant_type=" + grantType
  35 + + "&username=" + username
  36 + + "&password=" + password
  37 + + '&scope=user.read user.write',
38 method: 'POST', 38 method: 'POST',
39 headers: { 39 headers: {
40 - 'tenant-id': '1', // 多租户编号,写死 40 + 'tenant-id': '1', // 多租户编号,写死
41 }, 41 },
42 success: function (result) { 42 success: function (result) {
43 if (result.code !== 0) { 43 if (result.code !== 0) {
@@ -57,9 +57,9 @@ @@ -57,9 +57,9 @@
57 </script> 57 </script>
58 </head> 58 </head>
59 <body> 59 <body>
60 - 账号:<input id="username" value="admin" /> <br />  
61 - 密码:<input id="password" value="admin123" > <br />  
62 - <button style="float: right; margin-top: 5px;" onclick="login()">登录</button> 60 +账号:<input id="username" value="admin" /> <br />
  61 +密码:<input id="password" value="admin123" > <br />
  62 +<button style="float: right; margin-top: 5px;" onclick="login()">登录</button>
63 </body> 63 </body>
64 <style> 64 <style>
65 body { /** 页面居中 */ 65 body { /** 页面居中 */