From b385fe4e8de94d35d1c3795feef95b1267592698 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=8F=E6=B2=AB=E8=8A=B1=E7=81=ABzzz=F0=9F=8C=99?= Date: Tue, 3 Dec 2024 20:54:41 +0800 Subject: [PATCH] [*] Complete OAuth2.0 authorize page --- src/App.vue | 5 + src/api/v2/app/index.ts | 5 + src/api/v2/app/info.api.ts | 13 ++ src/api/v2/auth/oauth/authorize.api.ts | 18 ++ src/api/v2/auth/oauth/index.ts | 6 +- src/api/v2/auth/oauth/permission/all.api.ts | 12 ++ src/api/v2/auth/oauth/permission/index.ts | 5 + src/api/v2/index.ts | 4 +- src/router/index.js | 25 +++ src/utils/request.js | 4 +- src/views/AppView.vue | 3 + src/views/auth/oauth/AppAuthView.vue | 208 ++++++++++++++++++++ 12 files changed, 303 insertions(+), 5 deletions(-) create mode 100644 src/api/v2/app/index.ts create mode 100644 src/api/v2/app/info.api.ts create mode 100644 src/api/v2/auth/oauth/authorize.api.ts create mode 100644 src/api/v2/auth/oauth/permission/all.api.ts create mode 100644 src/api/v2/auth/oauth/permission/index.ts create mode 100644 src/views/AppView.vue create mode 100644 src/views/auth/oauth/AppAuthView.vue diff --git a/src/App.vue b/src/App.vue index bb04244..a463f53 100644 --- a/src/App.vue +++ b/src/App.vue @@ -151,6 +151,11 @@ async function fetchUserInfo() { watch( () => route.meta, (value) => { + if (value.noSidebar) { + showMainSidebar.value = false + showGuestSidebar.value = false + return + } if (value.needLogin) { showMainSidebar.value = true showGuestSidebar.value = false diff --git a/src/api/v2/app/index.ts b/src/api/v2/app/index.ts new file mode 100644 index 0000000..ecd3e2d --- /dev/null +++ b/src/api/v2/app/index.ts @@ -0,0 +1,5 @@ +import info from './info.api' + +export default { + info: info +} \ No newline at end of file diff --git a/src/api/v2/app/info.api.ts b/src/api/v2/app/info.api.ts new file mode 100644 index 0000000..c8800f0 --- /dev/null +++ b/src/api/v2/app/info.api.ts @@ -0,0 +1,13 @@ +//@ts-ignore +import { get } from '@/utils/request' +import base from '@/api/base' + +const info = async (user_id: number, app_id: number) => { + const rs = get(`${base.api_v2_url}/app/info`, { + user_id: user_id, + app_id: app_id, + }) + return base.buildResponse(await rs) +} + +export default info diff --git a/src/api/v2/auth/oauth/authorize.api.ts b/src/api/v2/auth/oauth/authorize.api.ts new file mode 100644 index 0000000..9b73698 --- /dev/null +++ b/src/api/v2/auth/oauth/authorize.api.ts @@ -0,0 +1,18 @@ +//@ts-ignore +import { post } from '@/utils/request' +import base from '@/api/base' + +const authorize = async ( + user_id: number, + app_id: number, + request_permission_ids: Array, +) => { + const rs = post(`${base.api_v2_url}/auth/oauth/authorize`, { + user_id: user_id, + app_id: app_id, + request_permission_ids: request_permission_ids + }) + return base.buildResponse(await rs) +} + +export default authorize diff --git a/src/api/v2/auth/oauth/index.ts b/src/api/v2/auth/oauth/index.ts index 2d2eb78..de12ff9 100644 --- a/src/api/v2/auth/oauth/index.ts +++ b/src/api/v2/auth/oauth/index.ts @@ -1,5 +1,9 @@ import qq from './qq' +import permission from './permission' +import authorize from './authorize.api' export default { - qq: qq + qq: qq, + permission: permission, + authorize: authorize } diff --git a/src/api/v2/auth/oauth/permission/all.api.ts b/src/api/v2/auth/oauth/permission/all.api.ts new file mode 100644 index 0000000..a349bf5 --- /dev/null +++ b/src/api/v2/auth/oauth/permission/all.api.ts @@ -0,0 +1,12 @@ +//@ts-ignore +import { get } from '@/utils/request' +import base from '@/api/base' + +const all = async (user_id: number) => { + const rs = get(`${base.api_v2_url}/auth/oauth/permission/all`, { + user_id: user_id, + }) + return base.buildResponse(await rs) +} + +export default all diff --git a/src/api/v2/auth/oauth/permission/index.ts b/src/api/v2/auth/oauth/permission/index.ts new file mode 100644 index 0000000..c336f37 --- /dev/null +++ b/src/api/v2/auth/oauth/permission/index.ts @@ -0,0 +1,5 @@ +import all from './all.api' + +export default { + all: all +} \ No newline at end of file diff --git a/src/api/v2/index.ts b/src/api/v2/index.ts index 9fcfa46..aee516d 100644 --- a/src/api/v2/index.ts +++ b/src/api/v2/index.ts @@ -9,6 +9,7 @@ import user from './user' import email from './email' import notice from './notice' import minecraft from './minecraft' +import app from './app' export default { user: user, @@ -21,5 +22,6 @@ export default { sign: sign, icp: icp, notice: notice, - minecraft: minecraft + minecraft: minecraft, + app: app } diff --git a/src/router/index.js b/src/router/index.js index b2561b9..c62b609 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -72,6 +72,21 @@ const routes = [ } }, component: () => import('@views/auth/ResetPasswordView.vue') + }, + { + path: 'oauth', + children: [ + { + path: 'authorize', + name: 'OAuthAuthorize', + meta: { + title: 'OAuth 授权界面', + needLogin: true, + noSidebar: true + }, + component: () => import('@views/auth/oauth/AppAuthView.vue') + } + ] } ] }, @@ -160,6 +175,16 @@ const routes = [ }, component: () => import('@views/IcpCheckView.vue') }, + { + path: '/app', + name: 'App', + meta: { + title: '应用', + keepAlive: true, + needLogin: true + }, + component: () => import('@views/AppView.vue') + }, { path: '/games', children: [ diff --git a/src/utils/request.js b/src/utils/request.js index e51bf41..3e1e5d6 100644 --- a/src/utils/request.js +++ b/src/utils/request.js @@ -23,8 +23,6 @@ const instance = axios.create({ const tokenDomains = ['api.locyanfrp.cn', 'api-v2.locyanfrp.cn', 'localhost'] -// post请求的时候,我们需要加上一个请求头,所以可以在这里进行一个默认的设置,即设置post的请求头为 -axios.defaults.headers.post['Content-Type'] = 'multipart/form-data;charset=UTF-8' // 添加请求拦截器 instance.interceptors.request.use( async (config) => { @@ -119,7 +117,7 @@ export async function get(url, params) { * @param headers */ export async function post(url, params, headers = {}) { - return await instance.post(url, QS.stringify(params), { + return await instance.post(url, QS.stringify(params, { arrayFormat: 'repeat' }), { headers: { ...headers, 'Content-Type': 'application/x-www-form-urlencoded' } }) } diff --git a/src/views/AppView.vue b/src/views/AppView.vue new file mode 100644 index 0000000..7cf6546 --- /dev/null +++ b/src/views/AppView.vue @@ -0,0 +1,3 @@ + diff --git a/src/views/auth/oauth/AppAuthView.vue b/src/views/auth/oauth/AppAuthView.vue new file mode 100644 index 0000000..d10687a --- /dev/null +++ b/src/views/auth/oauth/AppAuthView.vue @@ -0,0 +1,208 @@ + + + + +