增加getOneIDToken方法
This commit is contained in:
parent
79f27be41d
commit
4a86455458
|
@ -9,6 +9,15 @@ export function login(data) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ONEID登录功能(通过code获取对应的用户token)
|
||||||
|
export function getOneIdToken(code) {
|
||||||
|
return request({
|
||||||
|
url: '/WRD-admin/oneIDLogin',
|
||||||
|
method: 'get',
|
||||||
|
params: { code }
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
export function getInfo() {
|
export function getInfo() {
|
||||||
return request({
|
return request({
|
||||||
url: '/WRD-admin/sys/user/info',
|
url: '/WRD-admin/sys/user/info',
|
||||||
|
|
|
@ -8,7 +8,7 @@ import getPageTitle from '@/utils/get-page-title'
|
||||||
|
|
||||||
NProgress.configure({ showSpinner: false }) // NProgress Configuration
|
NProgress.configure({ showSpinner: false }) // NProgress Configuration
|
||||||
|
|
||||||
const whiteList = ['/login'] // no redirect whitelist
|
const whiteList = ['/login', '/callback'] // no redirect whitelist
|
||||||
|
|
||||||
router.beforeEach(async(to, from, next) => {
|
router.beforeEach(async(to, from, next) => {
|
||||||
// start progress bar
|
// start progress bar
|
||||||
|
@ -21,7 +21,7 @@ router.beforeEach(async(to, from, next) => {
|
||||||
const hasToken = getToken()
|
const hasToken = getToken()
|
||||||
|
|
||||||
if (hasToken) {
|
if (hasToken) {
|
||||||
if (to.path === '/login') {
|
if (to.path === '/login' || to.path === '/callback') {
|
||||||
// if is logged in, redirect to the home page
|
// if is logged in, redirect to the home page
|
||||||
next({ path: '/nav' })
|
next({ path: '/nav' })
|
||||||
NProgress.done()
|
NProgress.done()
|
||||||
|
@ -47,7 +47,6 @@ router.beforeEach(async(to, from, next) => {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
/* has no token*/
|
/* has no token*/
|
||||||
|
|
||||||
if (whiteList.indexOf(to.path) !== -1) {
|
if (whiteList.indexOf(to.path) !== -1) {
|
||||||
// in the free login whitelist, go directly
|
// in the free login whitelist, go directly
|
||||||
next()
|
next()
|
||||||
|
|
|
@ -1,59 +1,58 @@
|
||||||
<template>
|
<template>
|
||||||
<div class="main-box" />
|
<div class="main-box" />
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { mapGetters } from 'vuex'
|
import { mapGetters } from 'vuex'
|
||||||
import { getOneIdToken } from '@/api/user'
|
import { getOneIdToken } from '@/api/user'
|
||||||
export default {
|
export default {
|
||||||
name: 'CallBack',
|
name: 'CallBack',
|
||||||
computed: {
|
computed: {
|
||||||
...mapGetters([
|
...mapGetters([
|
||||||
'name'
|
'name'
|
||||||
])
|
])
|
||||||
},
|
},
|
||||||
async mounted() {
|
async mounted() {
|
||||||
debugger
|
debugger
|
||||||
// 获取 URL 参数中的 code
|
// 获取 URL 参数中的 code
|
||||||
// const urlParams = new URLSearchParams(window.location.hash.substring(1))
|
// const urlParams = new URLSearchParams(window.location.hash.substring(1))
|
||||||
// const code = urlParams.get('code')
|
// const code = urlParams.get('code')
|
||||||
// alert('callback page')
|
// alert('callback page')
|
||||||
// this.$router.push({ path: '/nav' })
|
// this.$router.push({ path: '/nav' })
|
||||||
const urlParams = new URLSearchParams(window.location.search)
|
const urlParams = new URLSearchParams(window.location.search)
|
||||||
const code = urlParams.get('code')
|
const code = urlParams.get('code')
|
||||||
// 在这里可以将 code 发送到后端进行处理
|
// 在这里可以将 code 发送到后端进行处理
|
||||||
if (code) {
|
if (code) {
|
||||||
// 发送 code 给后端进行验证和处理
|
// 发送 code 给后端进行验证和处理
|
||||||
const response = await getOneIdToken(code)
|
const response = await getOneIdToken(code)
|
||||||
console.log(response)
|
console.log(response)
|
||||||
if (response) {
|
if (response) {
|
||||||
// console.log('response.Token:' + response.Token)
|
// console.log('response.Token:' + response.Token)
|
||||||
// 存token
|
// 存token
|
||||||
this.$store.dispatch('user/commitToken', response)
|
this.$store.dispatch('user/commitToken', response)
|
||||||
// 重新加载路由 这里不对
|
// 重新加载路由 这里不对
|
||||||
// resetRouter() 这个没用,还把你的路由破坏了
|
// resetRouter() 这个没用,还把你的路由破坏了
|
||||||
// console.log(this.$store.state.user, this.$store.state.token)
|
// console.log(this.$store.state.user, this.$store.state.token)
|
||||||
this.$router.push({ path: '/nav' })
|
this.$router.push({ path: '/nav' })
|
||||||
} else {
|
|
||||||
console.log('No token found with code')
|
|
||||||
// window.location.href = 'https://api.oneid.siemens.com.cn/api/bff/v1.2/developer/ciam/oauth/authorize?client_id=1b867769c8cb221fb7fdb0f8beba6138TwXkI4mX8um&response_type=code&redirect_uri=http://csdc.siemens.com.cn:8001/#/callback&scope=openid phone email profile user:ciam:commonapi'
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
// 如果没有 code,则处理错误, 跳转回登录页面
|
console.log('No token found with code')
|
||||||
console.error('No code found in URL parameters.')
|
|
||||||
// window.location.href = 'https://api.oneid.siemens.com.cn/api/bff/v1.2/developer/ciam/oauth/authorize?client_id=1b867769c8cb221fb7fdb0f8beba6138TwXkI4mX8um&response_type=code&redirect_uri=http://csdc.siemens.com.cn:8001/#/callback&scope=openid phone email profile user:ciam:commonapi'
|
// window.location.href = 'https://api.oneid.siemens.com.cn/api/bff/v1.2/developer/ciam/oauth/authorize?client_id=1b867769c8cb221fb7fdb0f8beba6138TwXkI4mX8um&response_type=code&redirect_uri=http://csdc.siemens.com.cn:8001/#/callback&scope=openid phone email profile user:ciam:commonapi'
|
||||||
// window.location.href = 'https://oneid.siemens.com.cn/frontend/login?idaasAppId=siemens_ciam2'
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
// 如果没有 code,则处理错误, 跳转回登录页面
|
||||||
|
console.error('No code found in URL parameters.')
|
||||||
|
// window.location.href = 'https://api.oneid.siemens.com.cn/api/bff/v1.2/developer/ciam/oauth/authorize?client_id=1b867769c8cb221fb7fdb0f8beba6138TwXkI4mX8um&response_type=code&redirect_uri=http://csdc.siemens.com.cn:8001/#/callback&scope=openid phone email profile user:ciam:commonapi'
|
||||||
|
// window.location.href = 'https://oneid.siemens.com.cn/frontend/login?idaasAppId=siemens_ciam2'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
}
|
||||||
|
</script>
|
||||||
<style lang="scss" scoped>
|
|
||||||
.main-box {
|
<style lang="scss" scoped>
|
||||||
background-image: url("../../assets/dashboard-background.png");
|
.main-box {
|
||||||
background-size: 100% 100%;
|
background-image: url("../../assets/dashboard-background.png");
|
||||||
background-repeat: no-repeat;
|
background-size: 100% 100%;
|
||||||
height: 100vh;
|
background-repeat: no-repeat;
|
||||||
}
|
height: 100vh;
|
||||||
</style>
|
}
|
||||||
|
</style>
|
||||||
|
|
Loading…
Reference in New Issue