71 lines
1.8 KiB
TypeScript
71 lines
1.8 KiB
TypeScript
/** @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 {
|
|
// remove unneeded "=" padding
|
|
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);
|
|
}
|
|
let pathName = window.location.pathname;
|
|
console.log("start Path-name: '" + pathName + "'");
|
|
console.log("check with: '" + environment.applName + "/sso/" + "'");
|
|
if (pathName.startsWith("/sso/") || pathName.startsWith(environment.applName + "/sso/")) {
|
|
return this.utf8_to_b64('home');
|
|
}
|
|
if (pathName.startsWith(environment.applName + "/sso/")) {
|
|
pathName = pathName.substring(environment.applName.length + 1);
|
|
}
|
|
return this.utf8_to_b64(pathName);
|
|
}
|
|
/**
|
|
* 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);
|
|
}
|
|
}
|
|
|