ssoLogin.js
2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import HtProgress from 'nprogress'
import store from '@/store'
import {
recordRoute,
routesWhiteList,
progressBar,
tokenName,
casTokenName,
oauthTokenName,
} from '@/config'
export default function (to, from, next) {
// 白名单页面
if (
routesWhiteList.indexOf(to.path) !== -1 ||
routesWhiteList.indexOf(to.name) !== -1
) {
next()
} else if (to.query && to.query[tokenName]) {
// 先跳转到加载中页面
next({ path: '/loading' })
store
.dispatch('user/authentication', to.query)
.then(() => {
// 鉴权完成后再跳转回来
setTimeout(() => {
next({ ...to, replace: true })
}, 100)
})
.catch(() => {
next({ path: '/500', replace: true })
})
} else if (window.ssoConfig.mode == 'cas') {
// cas单点登录
if (to.query && to.query[casTokenName]) {
const ticket = to.query[casTokenName]
store
.dispatch('user/ssoLogin', {
ticket,
service: window.location.href.split('?')[0],
})
.then(() => {
next({ ...to, replace: true })
})
.catch(() => {
next({ path: '/500', replace: true })
})
} else {
window.location.href = `${window.ssoConfig.url}?service=${window.location.href}`
}
} else if (window.ssoConfig.mode == 'oauth') {
// oauth单点登录
if (to.query && to.query[oauthTokenName]) {
const code = to.query[oauthTokenName]
store
.dispatch('user/ssoLogin', {
code,
service: window.location.href.split('?')[0],
})
.then(() => {
next({ ...to, replace: true })
})
.catch(() => {
next({ path: '/500', replace: true })
})
} else {
window.location.href = `${window.ssoConfig.url}?response_type=code&client_id=${window.ssoConfig.clientId}&redirect_uri=${window.location.href}`
}
} else {
if (recordRoute) {
next(`/login?redirect=${to.fullPath}`)
} else {
next('/login')
}
if (progressBar) HtProgress.done()
}
}