/** @file * @author Edouard DUPIN * @copyright 2018, Edouard DUPIN, all right reserved * @license PROPRIETARY (see license file) */ import { Injectable } from '@angular/core'; import { environment } from '../../environments/environment'; @Injectable() export class SSOService { constructor() { console.log('Start SSOService'); } utf8_to_b64( str:string ): string { return window.btoa(unescape(encodeURIComponent( str ))).replace("=", ""); } b64_to_utf8( str:string ): string { return decodeURIComponent(escape(window.atob( str ))); } /** * Request SSO connection */ hashLocalData(data?: string): string { if (data != undefined) { return this.utf8_to_b64(data); } return this.utf8_to_b64('home'); } /** * Request SSO connection */ unHashLocalData(data: string): string { return this.b64_to_utf8(data); } /** * Request SSO connection */ requestSignIn(name?: string): void { window.location.href = environment.ssoSignIn + this.hashLocalData(name); } /** * Request SSO Disconnect */ requestSignOut(name?: string): void { if (name === undefined) { name = 'home'; } window.location.href = environment.ssoSignOut + this.hashLocalData(name); } /** * Request SSO signUp */ requestSignUp(name?: string): void { window.location.href = environment.ssoSignUp + this.hashLocalData(name); } }