2020-07-16 15:18:25 +02:00
|
|
|
import { Component } from '@angular/core';
|
|
|
|
import {
|
|
|
|
ActivatedRoute,
|
|
|
|
Router,
|
|
|
|
} from '@angular/router';
|
|
|
|
|
|
|
|
import { ApiService } from 'jslib/abstractions/api.service';
|
|
|
|
import { AuthService } from 'jslib/abstractions/auth.service';
|
|
|
|
import { CryptoFunctionService } from 'jslib/abstractions/cryptoFunction.service';
|
|
|
|
import { I18nService } from 'jslib/abstractions/i18n.service';
|
|
|
|
import { PasswordGenerationService } from 'jslib/abstractions/passwordGeneration.service';
|
|
|
|
import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service';
|
|
|
|
import { StateService } from 'jslib/abstractions/state.service';
|
|
|
|
import { StorageService } from 'jslib/abstractions/storage.service';
|
|
|
|
|
2020-08-13 20:32:07 +02:00
|
|
|
import { SsoComponent as BaseSsoComponent } from 'jslib/angular/components/sso.component';
|
2020-07-16 15:18:25 +02:00
|
|
|
|
2020-08-20 22:39:05 +02:00
|
|
|
const IdentifierStorageKey = 'ssoOrgIdentifier';
|
|
|
|
|
2020-07-16 15:18:25 +02:00
|
|
|
@Component({
|
|
|
|
selector: 'app-sso',
|
|
|
|
templateUrl: 'sso.component.html',
|
|
|
|
})
|
2020-08-13 20:32:07 +02:00
|
|
|
export class SsoComponent extends BaseSsoComponent {
|
|
|
|
constructor(authService: AuthService, router: Router,
|
|
|
|
i18nService: I18nService, route: ActivatedRoute,
|
|
|
|
storageService: StorageService, stateService: StateService,
|
|
|
|
platformUtilsService: PlatformUtilsService, apiService: ApiService,
|
|
|
|
cryptoFunctionService: CryptoFunctionService,
|
|
|
|
passwordGenerationService: PasswordGenerationService) {
|
|
|
|
super(authService, router, i18nService, route, storageService, stateService, platformUtilsService,
|
|
|
|
apiService, cryptoFunctionService, passwordGenerationService);
|
|
|
|
this.redirectUri = window.location.origin + '/sso-connector.html';
|
|
|
|
this.clientId = 'web';
|
2020-07-16 15:18:25 +02:00
|
|
|
}
|
2020-08-20 22:39:05 +02:00
|
|
|
|
|
|
|
async ngOnInit() {
|
|
|
|
super.ngOnInit();
|
|
|
|
const queryParamsSub = this.route.queryParams.subscribe(async (qParams) => {
|
|
|
|
if (qParams.identifier != null) {
|
|
|
|
this.identifier = qParams.identifier;
|
|
|
|
} else {
|
|
|
|
const storedIdentifier = await this.storageService.get<string>(IdentifierStorageKey);
|
|
|
|
if (storedIdentifier != null) {
|
|
|
|
this.identifier = storedIdentifier;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (queryParamsSub != null) {
|
|
|
|
queryParamsSub.unsubscribe();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async submit() {
|
|
|
|
await this.storageService.save(IdentifierStorageKey, this.identifier);
|
2020-11-25 22:57:11 +01:00
|
|
|
if (this.clientId === 'browser') {
|
2020-12-22 17:28:58 +01:00
|
|
|
document.cookie = `ssoHandOffMessage=${this.i18nService.t('ssoHandOff')};SameSite=strict`;
|
2020-11-25 22:57:11 +01:00
|
|
|
}
|
2020-08-20 22:39:05 +02:00
|
|
|
super.submit();
|
|
|
|
}
|
2020-07-16 15:18:25 +02:00
|
|
|
}
|