From 88aca444cf5cca49f8004ce94a05a9008d271f66 Mon Sep 17 00:00:00 2001 From: Dyakov Roman Date: Fri, 17 Feb 2023 15:38:54 +0300 Subject: [PATCH] OAuth endpoint --- .env.development | 3 +- .env.production | 2 +- package.json | 4 +- src/App.vue | 28 ++---------- src/components/HelloWorld.vue | 59 ------------------------ src/router/index.js | 84 ++++++++++++++++++++++++++--------- src/views/AboutView.vue | 5 --- src/views/AuthView.vue | 9 ++++ src/views/HomeView.vue | 18 -------- src/views/RegisterView.vue | 9 ++++ src/views/ResetPwdView.vue | 9 ++++ src/views/UserView.vue | 9 ++++ 12 files changed, 107 insertions(+), 132 deletions(-) delete mode 100644 src/components/HelloWorld.vue delete mode 100644 src/views/AboutView.vue create mode 100644 src/views/AuthView.vue delete mode 100644 src/views/HomeView.vue create mode 100644 src/views/RegisterView.vue create mode 100644 src/views/ResetPwdView.vue create mode 100644 src/views/UserView.vue diff --git a/.env.development b/.env.development index 82d0a67..4e669c6 100644 --- a/.env.development +++ b/.env.development @@ -7,5 +7,4 @@ VUE_APP_API_REPORT=https://report.api.test.profcomff.com VUE_APP_API_TIMETABLE=https://timetable.api.test.profcomff.com VUE_APP_API_NAVBAR=https://navbar.api.test.profcomff.com VUE_APP_API_MARKETING=https://marketing.api.test.profcomff.com -VUE_APP_FEEDBACK_FORM=https://forms.yandex.ru/u/635d013b068ff0587320bfc9/ - \ No newline at end of file +VUE_APP_API_AUTH=https://auth.api.test.profcomff.com diff --git a/.env.production b/.env.production index 786b1f6..244a324 100644 --- a/.env.production +++ b/.env.production @@ -7,4 +7,4 @@ VUE_APP_API_REPORT=https://report.api.profcomff.com VUE_APP_API_TIMETABLE=https://timetable.api.profcomff.com VUE_APP_API_NAVBAR=https://navbar.api.profcomff.com VUE_APP_API_MARKETING=https://marketing.api.profcomff.com - \ No newline at end of file +VUE_APP_API_AUTH=https://auth.api.profcomff.com diff --git a/package.json b/package.json index 50828fa..c97450b 100644 --- a/package.json +++ b/package.json @@ -1,9 +1,9 @@ { - "name": "@profcomff/auth", + "name": "@profcomff/auth-webapp", "version": "0.1.0", "private": true, "scripts": { - "serve": "vue-cli-service serve", + "start": "vue-cli-service serve --port 9006", "build": "vue-cli-service build", "lint": "vue-cli-service lint", "serve:standalone": "vue-cli-service serve --mode standalone" diff --git a/src/App.vue b/src/App.vue index e0dbc3a..d7767fa 100644 --- a/src/App.vue +++ b/src/App.vue @@ -1,31 +1,9 @@ - - - \ No newline at end of file + diff --git a/src/components/HelloWorld.vue b/src/components/HelloWorld.vue deleted file mode 100644 index b2c8940..0000000 --- a/src/components/HelloWorld.vue +++ /dev/null @@ -1,59 +0,0 @@ - - - - - - diff --git a/src/router/index.js b/src/router/index.js index d3a856e..d3fda2d 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -1,25 +1,69 @@ -import { createRouter, createWebHistory } from 'vue-router' -import HomeView from '../views/HomeView.vue' +import { createRouter, createWebHistory } from 'vue-router'; const routes = [ - { - path: '/', - name: 'home', - component: HomeView - }, - { - path: '/about', - name: 'about', - // route level code-splitting - // this generates a separate chunk (about.[hash].js) for this route - // which is lazy-loaded when the route is visited. - component: () => import(/* webpackChunkName: "about" */ '../views/AboutView.vue') - } -] + { + path: '/auth', + component: () => import('../views/AuthView.vue'), + }, + { + path: '/auth/register', + component: () => import('../views/RegisterView.vue'), + }, + { + path: '/auth/reset_password', + component: () => import('../views/ResetPwdView.vue'), + }, + { + path: '/auth/oauth-authorized/:oauthProvider', + component: () => {}, + meta: { oauthProvider: true }, + }, + { + path: '/user', + component: () => import('../views/UserView.vue'), + meta: { userNeededScopes: [] }, + }, +]; const router = createRouter({ - history: createWebHistory(process.env.BASE_URL), - routes -}) + history: createWebHistory(process.env.BASE_URL), + routes, +}); -export default router +router.beforeEach(async (to, from) => { + // Log to marketing API + fetch(`${process.env.VUE_APP_API_MARKETING}/action`, { + method: 'POST', + cache: 'no-cache', + redirect: 'follow', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ + user_id: localStorage.getItem('marketing-id'), + action: 'route to', + path_from: from.fullPath || null, + path_to: to.fullPath || null, + }), + }).catch(); + + if (to.meta.oauthProvider) { + console.log(to.query); + try { + let resp = await fetch( + `${process.env.VUE_APP_API_AUTH}/${to.params.oauthProvider}/login`, + { + method: 'POST', + cache: 'no-cache', + redirect: 'follow', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify(to.query), + }, + ).json(); + if (resp.token) return { path: '/user' }; + else return { path: '/auth' }; + } catch (error) { + return { path: '/auth' }; + } + } +}); + +export default router; diff --git a/src/views/AboutView.vue b/src/views/AboutView.vue deleted file mode 100644 index 3fa2807..0000000 --- a/src/views/AboutView.vue +++ /dev/null @@ -1,5 +0,0 @@ - diff --git a/src/views/AuthView.vue b/src/views/AuthView.vue new file mode 100644 index 0000000..5274197 --- /dev/null +++ b/src/views/AuthView.vue @@ -0,0 +1,9 @@ + + + + + diff --git a/src/views/HomeView.vue b/src/views/HomeView.vue deleted file mode 100644 index e8d96d7..0000000 --- a/src/views/HomeView.vue +++ /dev/null @@ -1,18 +0,0 @@ - - - diff --git a/src/views/RegisterView.vue b/src/views/RegisterView.vue new file mode 100644 index 0000000..cf13047 --- /dev/null +++ b/src/views/RegisterView.vue @@ -0,0 +1,9 @@ + + + + + diff --git a/src/views/ResetPwdView.vue b/src/views/ResetPwdView.vue new file mode 100644 index 0000000..6e9cd75 --- /dev/null +++ b/src/views/ResetPwdView.vue @@ -0,0 +1,9 @@ + + + + + diff --git a/src/views/UserView.vue b/src/views/UserView.vue new file mode 100644 index 0000000..f3b7ba8 --- /dev/null +++ b/src/views/UserView.vue @@ -0,0 +1,9 @@ + + + + +