Wrap sso login with pre-validation check (#160)
* Wrap sso login with pre-validation check * Add form promise for SSO preValidate * Removed boolean variable, .catch()
This commit is contained in:
parent
0bff8bcd56
commit
fa2b8e834b
|
@ -306,4 +306,6 @@ export abstract class ApiService {
|
|||
getActiveBearerToken: () => Promise<string>;
|
||||
fetch: (request: Request) => Promise<Response>;
|
||||
nativeFetch: (request: Request) => Promise<Response>;
|
||||
|
||||
preValidateSso: (identifier: string) => Promise<boolean>;
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@ export class SsoComponent {
|
|||
loggingIn = false;
|
||||
|
||||
formPromise: Promise<AuthResult>;
|
||||
initiateSsoFormPromise: Promise<any>;
|
||||
onSuccessfulLogin: () => Promise<any>;
|
||||
onSuccessfulLoginNavigate: () => Promise<any>;
|
||||
onSuccessfulLoginTwoFactorNavigate: () => Promise<any>;
|
||||
|
@ -67,8 +68,20 @@ export class SsoComponent {
|
|||
}
|
||||
|
||||
async submit(returnUri?: string, includeUserIdentifier?: boolean) {
|
||||
const authorizeUrl = await this.buildAuthorizeUrl(returnUri, includeUserIdentifier);
|
||||
this.platformUtilsService.launchUri(authorizeUrl, { sameWindow: true });
|
||||
this.initiateSsoFormPromise = this.preValidate();
|
||||
if (await this.initiateSsoFormPromise) {
|
||||
const authorizeUrl = await this.buildAuthorizeUrl(returnUri, includeUserIdentifier);
|
||||
this.platformUtilsService.launchUri(authorizeUrl, { sameWindow: true });
|
||||
}
|
||||
}
|
||||
|
||||
async preValidate(): Promise<boolean> {
|
||||
if (this.identifier == null || this.identifier === '') {
|
||||
this.platformUtilsService.showToast('error', this.i18nService.t('ssoValidationFailed'),
|
||||
this.i18nService.t('ssoIdentifierRequired'));
|
||||
return false;
|
||||
}
|
||||
return await this.apiService.preValidateSso(this.identifier);
|
||||
}
|
||||
|
||||
protected async buildAuthorizeUrl(returnUri?: string, includeUserIdentifier?: boolean): Promise<string> {
|
||||
|
|
|
@ -1040,6 +1040,35 @@ export class ApiService implements ApiServiceAbstraction {
|
|||
return fetch(request);
|
||||
}
|
||||
|
||||
async preValidateSso(identifier: string): Promise<boolean> {
|
||||
|
||||
if (identifier == null || identifier === '') {
|
||||
throw new Error('Organization Identifier was not provided.');
|
||||
}
|
||||
const headers = new Headers({
|
||||
'Accept': 'application/json',
|
||||
'Device-Type': this.deviceType,
|
||||
});
|
||||
if (this.customUserAgent != null) {
|
||||
headers.set('User-Agent', this.customUserAgent);
|
||||
}
|
||||
|
||||
const path = `/account/prevalidate?domainHint=${encodeURIComponent(identifier)}`;
|
||||
const response = await this.fetch(new Request(this.identityBaseUrl + path, {
|
||||
cache: 'no-store',
|
||||
credentials: this.getCredentials(),
|
||||
headers: headers,
|
||||
method: 'GET',
|
||||
}));
|
||||
|
||||
if (response.status === 200) {
|
||||
return true;
|
||||
} else {
|
||||
const error = await this.handleError(response, false);
|
||||
return Promise.reject(error);
|
||||
}
|
||||
}
|
||||
|
||||
private async send(method: 'GET' | 'POST' | 'PUT' | 'DELETE', path: string, body: any,
|
||||
authed: boolean, hasResponse: boolean): Promise<any> {
|
||||
const headers = new Headers({
|
||||
|
|
Loading…
Reference in New Issue