waiting for initialization
This commit is contained in:
@@ -5,39 +5,60 @@ import { createLogger } from '../utils/utils';
|
||||
const logger = createLogger('KeycloakInitializerService');
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class KeycloakInitializerService {
|
||||
private initialized = false;
|
||||
public initialized = false;
|
||||
|
||||
constructor(private keycloakService: KeycloakService) {}
|
||||
|
||||
async initialize(): Promise<void> {
|
||||
if (this.initialized) {
|
||||
return;
|
||||
}
|
||||
|
||||
const authenticated = await this.keycloakService.init({
|
||||
config: {
|
||||
url: environment.keycloak.url,
|
||||
realm: environment.keycloak.realm,
|
||||
clientId: environment.keycloak.clientId,
|
||||
},
|
||||
initOptions: {
|
||||
onLoad: 'check-sso',
|
||||
silentCheckSsoRedirectUri: (<any>window).location.origin + '/assets/silent-check-sso.html',
|
||||
flow: 'implicit',
|
||||
},
|
||||
// initOptions: {
|
||||
// pkceMethod: 'S256',
|
||||
// redirectUri: environment.keycloak.redirectUri,
|
||||
// checkLoginIframe: false,
|
||||
// },
|
||||
async initialize(): Promise<boolean> {
|
||||
return new Promise<boolean>(async (resolve, reject) => {
|
||||
try {
|
||||
await this.keycloakService.init({
|
||||
config: {
|
||||
url: environment.keycloak.url,
|
||||
realm: environment.keycloak.realm,
|
||||
clientId: environment.keycloak.clientId,
|
||||
},
|
||||
initOptions: {
|
||||
onLoad: 'check-sso',
|
||||
silentCheckSsoRedirectUri: (<any>window).location.origin + '/assets/silent-check-sso.html',
|
||||
// flow: 'implicit',
|
||||
},
|
||||
});
|
||||
this.initialized = true;
|
||||
resolve(true);
|
||||
} catch (error) {
|
||||
reject(error);
|
||||
}
|
||||
});
|
||||
const token = await this.keycloakService.getToken();
|
||||
logger.info(`--->${authenticated}:${token}`);
|
||||
// if (this.initialized) {
|
||||
// return;
|
||||
// }
|
||||
// logger.info(`###>calling keycloakService init ...`);
|
||||
// const authenticated = await this.keycloakService.init({
|
||||
// config: {
|
||||
// url: environment.keycloak.url,
|
||||
// realm: environment.keycloak.realm,
|
||||
// clientId: environment.keycloak.clientId,
|
||||
// },
|
||||
// initOptions: {
|
||||
// onLoad: 'check-sso',
|
||||
// silentCheckSsoRedirectUri: (<any>window).location.origin + '/assets/silent-check-sso.html',
|
||||
// // flow: 'implicit',
|
||||
// },
|
||||
// // initOptions: {
|
||||
// // pkceMethod: 'S256',
|
||||
// // redirectUri: environment.keycloak.redirectUri,
|
||||
// // checkLoginIframe: false,
|
||||
// // },
|
||||
// });
|
||||
// logger.info(`+++>authenticated: ${authenticated}`);
|
||||
// const token = await this.keycloakService.getToken();
|
||||
// logger.info(`--->${token}`);
|
||||
|
||||
this.initialized = true;
|
||||
// this.initialized = true;
|
||||
}
|
||||
|
||||
isInitialized(): boolean {
|
||||
return this.initialized;
|
||||
}
|
||||
// isInitialized(): boolean {
|
||||
// return this.initialized;
|
||||
// }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user