From 220c057e843a6f878b5a57f9f72c0988d998bc0e Mon Sep 17 00:00:00 2001 From: yangbin Date: Fri, 26 Jul 2024 19:56:29 +0800 Subject: [PATCH] =?UTF-8?q?OneID=E7=99=BB=E9=99=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/user.js | 7 +++++-- src/layout/components/Navbar.vue | 3 ++- src/permission.js | 4 +++- src/router/index.js | 2 +- src/store/modules/user.js | 11 +++++++++++ src/views/callback/index.vue | 15 ++++++++------- 6 files changed, 30 insertions(+), 12 deletions(-) diff --git a/src/api/user.js b/src/api/user.js index 7203a5e..130f396 100644 --- a/src/api/user.js +++ b/src/api/user.js @@ -10,11 +10,14 @@ export function login(data) { } // ONEID登录功能(通过code获取对应的用户token) -export function getOneIdToken(code) { +export function getOneIdToken(param) { return request({ + // 本地测试接口 + // url: '/WRD-admin/oneIDLocalLogin', + // 线上正式接口 url: '/WRD-admin/oneIDLogin', method: 'get', - params: { code } + params: { param } }) } diff --git a/src/layout/components/Navbar.vue b/src/layout/components/Navbar.vue index 72a531e..fa25b55 100644 --- a/src/layout/components/Navbar.vue +++ b/src/layout/components/Navbar.vue @@ -101,7 +101,8 @@ export default { async logout() { await this.$store.dispatch('user/logout') // this.$router.push(`/login?redirect=${this.$route.fullPath}`); - this.$router.push(`/login`) + // this.$router.push(`/login`) + window.location.href = 'https://oneid.siemens.com.cn/frontend/login?idaasAppId=siemens_ciam2' }, // 修改个人信息回调 updatePersonalPassword() { diff --git a/src/permission.js b/src/permission.js index 49ce1fd..a268bd2 100644 --- a/src/permission.js +++ b/src/permission.js @@ -52,7 +52,9 @@ router.beforeEach(async(to, from, next) => { next() } else { // other pages that do not have permission to access are redirected to the login page. - next(`/login?redirect=${to.path}`) + // next(`/login?redirect=${to.path}`) + 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%20phone' + // 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://localhost:9528/callback&scope=openid%20phone' NProgress.done() } } diff --git a/src/router/index.js b/src/router/index.js index cff0c09..282c887 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -183,7 +183,7 @@ export const asyncRoutes = [ export const anyRoutes = { path: '*', redirect: '/404', hidden: true } const createRouter = () => new Router({ - mode: 'hash', + mode: 'history', scrollBehavior: () => ({ y: 0 }), routes: constantRoutes }) diff --git a/src/store/modules/user.js b/src/store/modules/user.js index 4e9c5bb..5f8eda8 100644 --- a/src/store/modules/user.js +++ b/src/store/modules/user.js @@ -143,6 +143,17 @@ const actions = { }) }, + // set token + commitToken({ commit }, token) { + return new Promise(resolve => { + commit('SET_TOKEN', token) + setToken(token) + const data = getToken() + console.log(data) + resolve() + }) + }, + // remove token resetToken({ commit }) { return new Promise(resolve => { diff --git a/src/views/callback/index.vue b/src/views/callback/index.vue index 9cce19b..f58a962 100644 --- a/src/views/callback/index.vue +++ b/src/views/callback/index.vue @@ -13,7 +13,6 @@ export default { ]) }, async mounted() { - debugger // 获取 URL 参数中的 code // const urlParams = new URLSearchParams(window.location.hash.substring(1)) // const code = urlParams.get('code') @@ -23,25 +22,27 @@ export default { const code = urlParams.get('code') // 在这里可以将 code 发送到后端进行处理 if (code) { + // 123 // 发送 code 给后端进行验证和处理 const response = await getOneIdToken(code) - console.log(response) if (response) { - // console.log('response.Token:' + response.Token) + console.log('response.Token:' + response.data.token) // 存token - this.$store.dispatch('user/commitToken', response) + this.$store.dispatch('user/commitToken', response.data.token) // 重新加载路由 这里不对 // resetRouter() 这个没用,还把你的路由破坏了 // console.log(this.$store.state.user, this.$store.state.token) 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' + 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%20phone' + // 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://localhost:9528/callback&scope=openid%20phone' } } 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://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%20phone' + // 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://localhost:9528/callback&scope=openid%20phone' // window.location.href = 'https://oneid.siemens.com.cn/frontend/login?idaasAppId=siemens_ciam2' } } @@ -50,7 +51,7 @@ export default {