Skip to content

Commit

Permalink
fix: setting login config in keycloak-auth service
Browse files Browse the repository at this point in the history
  • Loading branch information
SchettlerKoehler committed Jun 18, 2024
1 parent 04726af commit d8554d4
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions libs/angular-auth/src/lib/auth_services/keycloak-auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,14 @@ const KC_TOKEN_LS = 'onecx_kc_token'

@Injectable()
export class KeycloakAuthService implements AuthService {

kcConfig?: Record<string, unknown>

constructor(private keycloakService: KeycloakService, private configService: ConfigurationService) {}

public async init(config?: Record<string, unknown>): Promise<boolean> {
console.time('KeycloakAuthService')
this.kcConfig = config
let token = localStorage.getItem(KC_TOKEN_LS)
let idToken = localStorage.getItem(KC_ID_TOKEN_LS)
let refreshToken = localStorage.getItem(KC_REFRESH_TOKEN_LS)
Expand Down Expand Up @@ -55,13 +59,13 @@ export class KeycloakAuthService implements AuthService {
.init(kcOptions)
.catch((err) => {
console.log(`Keycloak err: ${err}, try force login`)
return this.keycloakService.login()
return this.keycloakService.login(config)
})
.then((loginOk) => {
if (loginOk) {
return this.keycloakService.getToken()
} else {
return this.keycloakService.login().then(() => 'login')
return this.keycloakService.login(config).then(() => 'login')
}
})
.then(() => {
Expand Down Expand Up @@ -113,7 +117,7 @@ export class KeycloakAuthService implements AuthService {
if (ke.type === KeycloakEventType.OnAuthLogout) {
console.log('SSO logout nav to root')
this.clearKCStateFromLocalstorage()
this.keycloakService.login()
this.keycloakService.login(this.kcConfig)
}
})
}
Expand Down Expand Up @@ -145,7 +149,7 @@ export class KeycloakAuthService implements AuthService {

async updateTokenIfNeeded(): Promise<boolean> {
if (!(await this.keycloakService.isLoggedIn())) {
return this.keycloakService.login().then(() => false)
return this.keycloakService.login(this.kcConfig).then(() => false)
} else {
return this.keycloakService.updateToken()
}
Expand Down

0 comments on commit d8554d4

Please sign in to comment.