From d217047cd48e9e02cf416ff5f445d01de47ae184 Mon Sep 17 00:00:00 2001 From: Daniel Gerhardt Date: Fri, 27 Sep 2019 16:14:38 +0200 Subject: [PATCH 1/2] Add support for SSO to auth service This implementation opens the SSO login page in a popup and retrieves authentication details from the API once the popup is closed. Components have not yet been adjusted to support SSO. --- .../services/http/authentication.service.ts | 31 +++++++++++++++++-- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/src/app/services/http/authentication.service.ts b/src/app/services/http/authentication.service.ts index 2af8374f..74bea520 100644 --- a/src/app/services/http/authentication.service.ts +++ b/src/app/services/http/authentication.service.ts @@ -1,7 +1,7 @@ -import { catchError, map } from 'rxjs/operators'; +import { catchError, map, concatMap, filter, take } from 'rxjs/operators'; import { Injectable } from '@angular/core'; import { User } from '../../models/user'; -import { Observable , of , BehaviorSubject } from 'rxjs'; +import { Observable, of, BehaviorSubject, timer } from 'rxjs'; import { UserRole } from '../../models/user-roles.enum'; import { DataStoreService } from '../util/data-store.service'; import { EventService } from '../util/event.service'; @@ -22,7 +22,8 @@ export class AuthenticationService { register: '/register', registered: '/registered', resetPassword: '/resetpassword', - guest: '/guest' + guest: '/guest', + sso: '/sso' }; private httpOptions = { headers: new HttpHeaders({}) @@ -89,6 +90,30 @@ export class AuthenticationService { return this.checkLogin(this.http.post(connectionUrl, null, this.httpOptions), userRole, true); } + /** + * Open the SSO login page in a popup and check the result. + * + * @param providerId ID of the SSO provider + * @param userRole User role for the UI + */ + loginViaSso(providerId: string, userRole: UserRole): Observable { + const ssoUrl = this.apiUrl.base + this.apiUrl.auth + this.apiUrl.sso + '/' + providerId; + const loginUrl = this.apiUrl.base + this.apiUrl.auth + this.apiUrl.login + '?refresh=true'; + const popupW = 500; + const popupH = 500; + const popupX = window.top.screenX + window.top.outerWidth / 2 - popupW / 2; + const popupY = window.top.screenY + window.top.outerHeight / 2 - popupH / 2; + const popup = window.open(ssoUrl, 'auth_popup', + `left=${popupX},top=${popupY},width=${popupW},height=${popupH},resizable`); + const auth = timer(0, 500).pipe( + map(() => popup.closed), + filter((closed) => closed), + concatMap(() => this.http.post(loginUrl, null, { withCredentials: true })), + take(1)); + + return this.checkLogin(auth, userRole, false); + } + register(email: string, password: string): Observable { const connectionUrl: string = this.apiUrl.base + this.apiUrl.user + this.apiUrl.register; -- GitLab From b8b903716645731d328e350fcd737096109a36f9 Mon Sep 17 00:00:00 2001 From: Daniel Gerhardt Date: Fri, 27 Sep 2019 17:53:27 +0200 Subject: [PATCH 2/2] Add SSO buttons to login dialog SSO login buttons are dynamically added based on the authentication provider config received from backend API. --- .../components/shared/login/login.component.html | 3 +++ .../components/shared/login/login.component.ts | 16 ++++++++++++++++ src/assets/i18n/home/de.json | 1 + src/assets/i18n/home/en.json | 1 + 4 files changed, 21 insertions(+) diff --git a/src/app/components/shared/login/login.component.html b/src/app/components/shared/login/login.component.html index c5ba17d4..a1dc6b35 100644 --- a/src/app/components/shared/login/login.component.html +++ b/src/app/components/shared/login/login.component.html @@ -25,6 +25,9 @@ +