RED-5700 - idp hint on login link
This commit is contained in:
parent
2b98f871ed
commit
03d63fc78e
@ -1,10 +1,11 @@
|
|||||||
import { HttpErrorResponse, HttpEvent, HttpHandler, HttpInterceptor, HttpRequest, HttpStatusCode } from '@angular/common/http';
|
import { HttpErrorResponse, HttpEvent, HttpHandler, HttpInterceptor, HttpRequest, HttpStatusCode } from '@angular/common/http';
|
||||||
import { Inject, Injectable, Optional } from '@angular/core';
|
import { inject, Inject, Injectable, Optional } from '@angular/core';
|
||||||
import { MonoTypeOperatorFunction, Observable, retry, throwError, timer } from 'rxjs';
|
import { MonoTypeOperatorFunction, Observable, retry, throwError, timer } from 'rxjs';
|
||||||
import { catchError, tap } from 'rxjs/operators';
|
import { catchError, tap } from 'rxjs/operators';
|
||||||
import { MAX_RETRIES_ON_SERVER_ERROR, SERVER_ERROR_SKIP_PATHS } from './tokens';
|
import { MAX_RETRIES_ON_SERVER_ERROR, SERVER_ERROR_SKIP_PATHS } from './tokens';
|
||||||
import { ErrorService } from './error.service';
|
import { ErrorService } from './error.service';
|
||||||
import { KeycloakService } from 'keycloak-angular';
|
import { KeycloakService } from 'keycloak-angular';
|
||||||
|
import { IqserConfigService } from '../services';
|
||||||
|
|
||||||
function updateSeconds(seconds: number) {
|
function updateSeconds(seconds: number) {
|
||||||
if (seconds === 0 || seconds === 1) {
|
if (seconds === 0 || seconds === 1) {
|
||||||
@ -47,6 +48,7 @@ export class ServerErrorInterceptor implements HttpInterceptor {
|
|||||||
constructor(
|
constructor(
|
||||||
private readonly _errorService: ErrorService,
|
private readonly _errorService: ErrorService,
|
||||||
private readonly _keycloakService: KeycloakService,
|
private readonly _keycloakService: KeycloakService,
|
||||||
|
private readonly _configService: IqserConfigService,
|
||||||
@Optional() @Inject(MAX_RETRIES_ON_SERVER_ERROR) private readonly _maxRetries: number,
|
@Optional() @Inject(MAX_RETRIES_ON_SERVER_ERROR) private readonly _maxRetries: number,
|
||||||
@Optional() @Inject(SERVER_ERROR_SKIP_PATHS) private readonly _skippedPaths: string[],
|
@Optional() @Inject(SERVER_ERROR_SKIP_PATHS) private readonly _skippedPaths: string[],
|
||||||
) {}
|
) {}
|
||||||
@ -58,6 +60,7 @@ export class ServerErrorInterceptor implements HttpInterceptor {
|
|||||||
if (error.status === HttpStatusCode.Unauthorized) {
|
if (error.status === HttpStatusCode.Unauthorized) {
|
||||||
window.location.href = this._keycloakService.getKeycloakInstance().createLoginUrl({
|
window.location.href = this._keycloakService.getKeycloakInstance().createLoginUrl({
|
||||||
redirectUri: window.location.href,
|
redirectUri: window.location.href,
|
||||||
|
idpHint: this._configService.values.OAUTH_IDP_HINT,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -39,10 +39,11 @@ function getKeycloakOptions(baseUrl: string, configService: IqserConfigService):
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function configureAutomaticRedirectToLoginScreen(keyCloakService: KeycloakService) {
|
function configureAutomaticRedirectToLoginScreen(keyCloakService: KeycloakService,configService: IqserConfigService) {
|
||||||
keyCloakService.getKeycloakInstance().onAuthRefreshError = () => {
|
keyCloakService.getKeycloakInstance().onAuthRefreshError = () => {
|
||||||
window.location.href = keyCloakService.getKeycloakInstance().createLoginUrl({
|
window.location.href = keyCloakService.getKeycloakInstance().createLoginUrl({
|
||||||
redirectUri: window.location.href,
|
redirectUri: window.location.href,
|
||||||
|
idpHint: configService.values.OAUTH_IDP_HINT,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -53,7 +54,7 @@ export function keycloakInitializer(
|
|||||||
baseUrl: string,
|
baseUrl: string,
|
||||||
): () => Promise<void> {
|
): () => Promise<void> {
|
||||||
const x = keycloakService.init(getKeycloakOptions(baseUrl, configService));
|
const x = keycloakService.init(getKeycloakOptions(baseUrl, configService));
|
||||||
return () => x.then(() => configureAutomaticRedirectToLoginScreen(keycloakService));
|
return () => x.then(() => configureAutomaticRedirectToLoginScreen(keycloakService, configService));
|
||||||
}
|
}
|
||||||
|
|
||||||
const components = [NamePipe, InitialsAvatarComponent, UserButtonComponent];
|
const components = [NamePipe, InitialsAvatarComponent, UserButtonComponent];
|
||||||
|
|||||||
@ -15,6 +15,7 @@ import { KeycloakProfile } from 'keycloak-js';
|
|||||||
import { IqserUser } from '../iqser-user.model';
|
import { IqserUser } from '../iqser-user.model';
|
||||||
import { IqserPermissionsService, IqserRolesService } from '../../permissions';
|
import { IqserPermissionsService, IqserRolesService } from '../../permissions';
|
||||||
import { HttpErrorResponse, HttpStatusCode } from '@angular/common/http';
|
import { HttpErrorResponse, HttpStatusCode } from '@angular/common/http';
|
||||||
|
import { IqserConfigService } from '../../services';
|
||||||
import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker';
|
import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
@ -30,6 +31,7 @@ export abstract class IqserUserService<
|
|||||||
protected readonly _currentUser$ = new BehaviorSubject<Class | undefined>(undefined);
|
protected readonly _currentUser$ = new BehaviorSubject<Class | undefined>(undefined);
|
||||||
protected readonly _baseHref = inject(BASE_HREF);
|
protected readonly _baseHref = inject(BASE_HREF);
|
||||||
protected readonly _toaster = inject(Toaster);
|
protected readonly _toaster = inject(Toaster);
|
||||||
|
protected readonly _configService = inject(IqserConfigService);
|
||||||
protected readonly _keycloakService = inject(KeycloakService);
|
protected readonly _keycloakService = inject(KeycloakService);
|
||||||
protected readonly _cacheApiService = inject(CacheApiService);
|
protected readonly _cacheApiService = inject(CacheApiService);
|
||||||
protected readonly _permissionsService = inject(IqserPermissionsService, { optional: true });
|
protected readonly _permissionsService = inject(IqserPermissionsService, { optional: true });
|
||||||
@ -69,6 +71,7 @@ export abstract class IqserUserService<
|
|||||||
await this._cacheApiService.wipeCaches();
|
await this._cacheApiService.wipeCaches();
|
||||||
window.location.href = this._keycloakService.getKeycloakInstance().createLoginUrl({
|
window.location.href = this._keycloakService.getKeycloakInstance().createLoginUrl({
|
||||||
redirectUri: window.location.origin + this._baseHref,
|
redirectUri: window.location.origin + this._baseHref,
|
||||||
|
idpHint: this._configService.values.OAUTH_IDP_HINT
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user