1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-16 08:13:42 +00:00

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:
Chad Scharf
2020-09-08 10:36:22 -04:00
committed by GitHub
parent 0bff8bcd56
commit fa2b8e834b
3 changed files with 46 additions and 2 deletions

View File

@@ -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({