From cf70d38e6ce5bf2dbf9925b93a6e0b0dd0280d96 Mon Sep 17 00:00:00 2001 From: Vladislav Markin Date: Sun, 26 Nov 2023 23:09:41 +0300 Subject: [PATCH 01/44] =?UTF-8?q?=D1=80=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7?= =?UTF-8?q?=D0=B0=D1=86=D0=B8=D1=8F=20openid?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- oidc-settings.js | 22 +++++++++++++++ package.json | 1 + src/frontend/auth/oidc-client.js | 32 ++++++++++++++++++++++ src/frontend/components/Layouts/Header.vue | 24 +++++++++++++++- src/frontend/index.js | 2 ++ src/frontend/router/routes.js | 16 +++++++++++ 6 files changed, 96 insertions(+), 1 deletion(-) create mode 100644 oidc-settings.js create mode 100644 src/frontend/auth/oidc-client.js diff --git a/oidc-settings.js b/oidc-settings.js new file mode 100644 index 00000000..c0dc1596 --- /dev/null +++ b/oidc-settings.js @@ -0,0 +1,22 @@ +import {Log, UserManager} from 'oidc-client-ts'; + +Log.setLogger(console); +Log.setLevel(Log.ERROR); + +const url = window.location.origin; + +export const settings = { + authority: 'http://localhost:8099/realms/dochub', + client_id: 'dochub', + redirect_uri: new URL('/login', url), + post_logout_redirect_uri: new URL('/logout', url), + response_type: 'code', + scope: 'openid', + response_mode: 'fragment', + automaticSilentRenew: true +}; + +export { + Log, + UserManager +}; diff --git a/package.json b/package.json index 220d8c19..462b0010 100644 --- a/package.json +++ b/package.json @@ -43,6 +43,7 @@ "mermaid": "10.6.1", "monaco-editor": "0.34.1", "mustache": "4.2.0", + "oidc-client-ts": "2.4.0", "semver": "7.5.4", "swagger-ui": "3.52.5", "uuid": "8.3.2", diff --git a/src/frontend/auth/oidc-client.js b/src/frontend/auth/oidc-client.js new file mode 100644 index 00000000..0587abc2 --- /dev/null +++ b/src/frontend/auth/oidc-client.js @@ -0,0 +1,32 @@ +export default { + login() { + window.OidcUserManager.signinRedirect() + .then(() => { + // eslint-disable-next-line no-console + console.log('User logged in'); + }) + .catch(error => { + // eslint-disable-next-line no-console + console.error(error); + }); + }, + logout() { + window.OidcUserManager.signoutRedirect() + .then(() => { + // eslint-disable-next-line no-console + console.log('User logged out'); + }) + .catch(error => { + // eslint-disable-next-line no-console + console.error(error); + }); + }, + async signinCallback() { + if (window.location.hash) { + await window.OidcUserManager.signinCallback(); + window.location.hash = ''; + } else { + window.location = window.origin + '/main'; + } + } +}; diff --git a/src/frontend/components/Layouts/Header.vue b/src/frontend/components/Layouts/Header.vue index 9f58f721..0d2440d7 100644 --- a/src/frontend/components/Layouts/Header.vue +++ b/src/frontend/components/Layouts/Header.vue @@ -14,6 +14,17 @@ DocHub + + + + + + + + + + {{ user || 'Login' }} + error @@ -41,6 +52,7 @@