feat: oidc-demo 适配 Spring Authorization Server
This commit is contained in:
@@ -10,16 +10,6 @@
|
||||
<body>
|
||||
<script>
|
||||
window.onload = function() {
|
||||
//url获取state
|
||||
let state = getQueryVariable('state');
|
||||
let localState = sessionStorage.getItem("state");
|
||||
//判断state防止CSRF攻击
|
||||
if (localState !== state) {
|
||||
alert('state参数无效!');
|
||||
let state = getState();
|
||||
sessionStorage.setItem("state", state);
|
||||
window.location = getAuthorizeUri(state);
|
||||
}
|
||||
//url获取code
|
||||
let code = getQueryVariable('code');
|
||||
|
||||
|
||||
@@ -16,10 +16,8 @@
|
||||
</div>
|
||||
<script>
|
||||
function login() {
|
||||
let state = getState();
|
||||
sessionStorage.setItem("visitUri", window.location.href);
|
||||
sessionStorage.setItem("state", state);
|
||||
window.location = getAuthorizeUri(state);
|
||||
window.location = getAuthorizeUri();
|
||||
}
|
||||
|
||||
window.onload = function() {
|
||||
|
||||
@@ -6,22 +6,14 @@ let uaaUri = 'http://127.0.0.1:9900/api-uaa/oauth/';
|
||||
//端口
|
||||
let port = 8082;
|
||||
|
||||
function getAuthorizeUri(state) {
|
||||
return uaaUri+'authorize?client_id='+clientId+'&redirect_uri=http://127.0.0.1:'+port+'/callback.html&scope=openid&response_type=code&state='+state;
|
||||
function getAuthorizeUri() {
|
||||
return uaaUri+'authorize?client_id='+clientId+'&redirect_uri=http://127.0.0.1:'+port+'/callback.html&scope=openid&response_type=code';
|
||||
}
|
||||
|
||||
function getLogoutUri(accessToken) {
|
||||
return uaaUri+'remove/token?redirect_uri=http://127.0.0.1:'+port+'/index.html&access_token='+accessToken;
|
||||
}
|
||||
|
||||
function getState() {
|
||||
let state='';
|
||||
for (let i = 0; i < 6; i++) {
|
||||
state += FULL_CHARTER[Math.floor(Math.random() * 52)];
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取url参数
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user