Skip to content

Commit

Permalink
✨ 添加 OAuth2 授权码流程相关页面
Browse files Browse the repository at this point in the history
  • Loading branch information
Hccake committed Oct 23, 2022
1 parent ebd3311 commit 49e26c3
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/permission.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ router.beforeEach((to, from, next) => {
if (to.path === '/user/login') {
next({ path: '/' })
NProgress.done()
}
else if (to.path === '/oauth2/authorize') {
next()
NProgress.done()
} else {
if (store.getters.userRouters.length === 0) {
store.dispatch('GenerateRoutes').then(() => {
Expand Down
4 changes: 4 additions & 0 deletions src/router/constantRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ export const constantRouters = [
path: '/redirect/:path*',
component: () => import(/* webpackChunkName: "user" */ '@/views/redirect/index')
},
{
path: '/oauth2/authorize',
component: () => import(/* webpackChunkName: "oauth2" */ '@/views/oauth2/OAuth2Authorize')
},
{
path: '/user',
component: UserLayout,
Expand Down
39 changes: 39 additions & 0 deletions src/views/oauth2/OAuth2Authorize.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<template>
<div />
</template>

<script>
import Vue from 'vue'
import { ACCESS_TOKEN } from '@/store/storage-types'
export default {
name: 'Oauth2Authorize',
mounted () {
debugger
// 校验 token 是否有效,有效则直接 redirect, 如果无效则跳转到 login 页面,return_to 的参数也带过去
// 登录页登录完成后,如果有 return_to 参数,则进行 redirect
// 获取当前地址栏携带的 return_to 参数
const route = this.$route
const returnTo = route.query.return_to
// 获取当前 token
const accessToken = Vue.ls.get(ACCESS_TOKEN)
if (accessToken) {
if (returnTo) {
// 有 return_to 则且已登录则直接重定向到授权地址
// return_to 参数必然会有后缀
window.location.href = returnTo + '&access_token=' + accessToken
} else {
this.$router.push('/')
}
} else {
this.$router.push({
path: '/user/login',
query: returnTo ? { return_to: returnTo } : {}
})
}
}
}
</script>

0 comments on commit 49e26c3

Please sign in to comment.