增加 yudao-sso-demo-by-password 示例,基于密码模式,实现 SSO 单点登录
parent
05951783de
commit
bf700ab1fc
|
@ -31,7 +31,7 @@ public class OAuth2Client {
|
||||||
*/
|
*/
|
||||||
public static final Long TENANT_ID = 1L;
|
public static final Long TENANT_ID = 1L;
|
||||||
|
|
||||||
private static final String CLIENT_ID = "yudao-sso-demo-by-code";
|
private static final String CLIENT_ID = "yudao-sso-demo-by-password";
|
||||||
private static final String CLIENT_SECRET = "test";
|
private static final String CLIENT_SECRET = "test";
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -13,31 +13,31 @@
|
||||||
*/
|
*/
|
||||||
function login() {
|
function login() {
|
||||||
const clientId = 'yudao-sso-demo-by-password'; // 可以改写成,你的 clientId
|
const clientId = 'yudao-sso-demo-by-password'; // 可以改写成,你的 clientId
|
||||||
const clientSecret = 'test'; // 可以改写成,你的 clientSecret
|
const clientSecret = 'test'; // 可以改写成,你的 clientSecret
|
||||||
const grantType = 'password'; // 密码模式
|
const grantType = 'password'; // 密码模式
|
||||||
|
|
||||||
// 账号 + 密码
|
// 账号 + 密码
|
||||||
const username = $('#username').val();
|
const username = $('#username').val();
|
||||||
const password = $('#password').val();
|
const password = $('#password').val();
|
||||||
if (username.length === 0 || password.length === 0) {
|
if (username.length === 0 || password.length === 0) {
|
||||||
alert('账号或密码未输入');
|
alert('账号或密码未输入');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 发起请求
|
// 发起请求
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: "http://127.0.0.1:48080/admin-api/system/oauth2/token?"
|
url: "http://127.0.0.1:48080/admin-api/system/oauth2/token?"
|
||||||
// 客户端
|
// 客户端
|
||||||
+ "client_id=" + clientId
|
+ "client_id=" + clientId
|
||||||
+ "&client_secret=" + clientSecret
|
+ "&client_secret=" + clientSecret
|
||||||
// 密码模式的参数
|
// 密码模式的参数
|
||||||
+ "&grant_type=" + grantType
|
+ "&grant_type=" + grantType
|
||||||
+ "&username=" + username
|
+ "&username=" + username
|
||||||
+ "&password=" + password
|
+ "&password=" + password
|
||||||
+ '&scope=user.read user.write',
|
+ '&scope=user.read user.write',
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'tenant-id': '1', // 多租户编号,写死
|
'tenant-id': '1', // 多租户编号,写死
|
||||||
},
|
},
|
||||||
success: function (result) {
|
success: function (result) {
|
||||||
if (result.code !== 0) {
|
if (result.code !== 0) {
|
||||||
|
@ -57,9 +57,9 @@
|
||||||
</script>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
账号:<input id="username" value="admin" /> <br />
|
账号:<input id="username" value="admin" /> <br />
|
||||||
密码:<input id="password" value="admin123" > <br />
|
密码:<input id="password" value="admin123" > <br />
|
||||||
<button style="float: right; margin-top: 5px;" onclick="login()">登录</button>
|
<button style="float: right; margin-top: 5px;" onclick="login()">登录</button>
|
||||||
</body>
|
</body>
|
||||||
<style>
|
<style>
|
||||||
body { /** 页面居中 */
|
body { /** 页面居中 */
|
||||||
|
|
Loading…
Reference in New Issue