Commit c00bfb1f by 展昭

redirectPath

parent 6c58a978
Showing with 23 additions and 6 deletions
......@@ -38,7 +38,7 @@ function getAccessToken(authcode) {
let commonPms = GetCommonPms();
let url = `${oidc_config.authority}/connect/token?${commonPms}`;
let pms = {
"client_id": oidc_config.client_id,
"client_id": oidc_config.client_id,
"client_secret": oidc_config.client_secret,
"grant_type": "auth_code",
"scope": "openid offline_access",
......@@ -46,9 +46,9 @@ function getAccessToken(authcode) {
}
axios.post(url, qs.stringify(pms)).then(res => {
if (res && res.status) {
console.log('res.data=',res.data);
console.log('res.data=', res.data);
const accessToken = res.data.access_token;
console.log('accessToken=',accessToken);
console.log('accessToken=', accessToken);
resolve(accessToken);
}
else {
......@@ -59,7 +59,7 @@ function getAccessToken(authcode) {
});
}
async function getToken(access_token, appid, next) {
async function getToken(access_token, appid, redirectPath) {
let pms = {
client_id: oidc_config.client_id,
client_secret: oidc_config.client_secret,
......@@ -79,7 +79,7 @@ async function getToken(access_token, appid, next) {
if (res.status == 200) {
const accessToken = res.data.access_token;
localStorage.setItem("token", accessToken);
next()
this.$router.push(redirectPath);
}
},
err => {
......@@ -91,17 +91,34 @@ async function getToken(access_token, appid, next) {
});
}
function getPathByTo(to, authcode_key) {
let toPath = to.path || "/";
for (let key in to.query) {
if (key == authcode_key) {
continue;
}
toPath += toPath.indexOf("?") > -1 ? "&" : "?";
toPath += `${key}=${to.query[key]}`;
}
toPath = toPath.indexOf('?') > -1 ? toPath + "&t=" + (new Date()).valueOf() : toPath + "?t=" + (new Date()).valueOf();
return toPath;
}
router.beforeEach((to, from, next) => {
const authcode = to.query.authCode || to.query.authcode;
const appid = to.query.appId || to.query.appid;
if (!!authcode && !!appid) {
getAccessToken(authcode).then(res => {
const token = res;
getToken(token, appid, next);
const redirectPath = getPathByTo(to, 'authcode');
getToken(token, appid, redirectPath);
}).catch(err => {
console.log('err=', err);
})
} else {
next()
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment