-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathinit-auth.ts
More file actions
54 lines (52 loc) · 1.72 KB
/
init-auth.ts
File metadata and controls
54 lines (52 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import { Location } from '@angular/common';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Environment } from '../../../environments/ienvironment';
import { AuthService } from './auth-service/auth.service';
import { HelperService } from '../../_services/helper.service';
export function initializeAuth(
authService: AuthService,
locationStrategy: Location,
http: HttpClient,
helperService: HelperService,
environment: Environment
): () => Promise<boolean> {
return () => {
if (environment.isLegacyLogin) {
return authService.init({});
}
return new Promise((resolve, reject) => {
http
.get('assets/environment.json', {
headers: new HttpHeaders().set('No-Bearer', 'true'),
})
.toPromise()
.then((result: any) => {
if (result.domainSubfolder) {
helperService.setDomainFolder(result.domainSubfolder);
}
helperService.setApiUrl(result.apiUrl);
helperService.setLegacyUrl(result.legacyUrl);
return resolve(
authService.init({
config: {
url: result.keycloakUrl,
realm: result.keycloakRealm,
clientId: result.keycloakClientId,
},
initOptions: {
enableLogging: !environment.production,
onLoad: 'check-sso',
silentCheckSsoRedirectUri: `${
window.location.origin
}${locationStrategy.prepareExternalUrl('/assets/silent-check-sso.html')}`,
},
loadUserProfileAtStartUp: true,
})
);
})
.catch((error) => {
reject(error);
});
});
};
}