Handle baseHref for Keycloak
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
9e7023c5f8
commit
d3ecbba6f4
|
@ -2,6 +2,7 @@ import {ActivatedRouteSnapshot, Router, RouterStateSnapshot, UrlTree} from '@ang
|
|||
|
||||
import {KeycloakAuthGuard, KeycloakService} from 'keycloak-angular';
|
||||
import {Injectable} from '@angular/core';
|
||||
import {Location} from "@angular/common";
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
|
@ -9,7 +10,8 @@ import {Injectable} from '@angular/core';
|
|||
export class AppAuthGuard extends KeycloakAuthGuard {
|
||||
|
||||
constructor(protected override readonly router: Router,
|
||||
protected readonly keycloak: KeycloakService) {
|
||||
protected readonly keycloak: KeycloakService,
|
||||
private readonly location: Location) {
|
||||
super(router, keycloak);
|
||||
}
|
||||
|
||||
|
@ -17,7 +19,7 @@ export class AppAuthGuard extends KeycloakAuthGuard {
|
|||
// Force the user to log in if currently unauthenticated.
|
||||
if (!this.authenticated || this.keycloak.isTokenExpired()) {
|
||||
await this.keycloak.login({
|
||||
redirectUri: window.location.origin + state.url,
|
||||
redirectUri: `${window.location.origin}${this.location.prepareExternalUrl(state.url)}`,
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -12,8 +12,9 @@ import {provideAnimations} from "@angular/platform-browser/animations";
|
|||
import {HTTP_INTERCEPTORS, provideHttpClient, withInterceptorsFromDi} from "@angular/common/http";
|
||||
import {ROOT_ROUTES} from "./app/app.routes";
|
||||
import "@angular/localize/init";
|
||||
import {Location} from "@angular/common";
|
||||
|
||||
function initializeKeycloak(keycloak: KeycloakService) {
|
||||
function initializeKeycloak(keycloak: KeycloakService, locationService: Location) {
|
||||
return () =>
|
||||
keycloak.init({
|
||||
config: {
|
||||
|
@ -23,8 +24,7 @@ function initializeKeycloak(keycloak: KeycloakService) {
|
|||
},
|
||||
initOptions: {
|
||||
onLoad: 'check-sso',
|
||||
silentCheckSsoRedirectUri:
|
||||
window.location.origin + '/assets/silent-check-sso.html',
|
||||
silentCheckSsoRedirectUri:`${window.location.origin}${locationService.prepareExternalUrl('/assets/silent-check-sso.html')}`,
|
||||
flow: "standard"
|
||||
},
|
||||
shouldAddToken: (request) => {
|
||||
|
@ -41,7 +41,7 @@ bootstrapApplication(AppComponent, {
|
|||
provide: APP_INITIALIZER,
|
||||
useFactory: initializeKeycloak,
|
||||
multi: true,
|
||||
deps: [KeycloakService],
|
||||
deps: [KeycloakService, Location],
|
||||
},
|
||||
provideRouter(ROOT_ROUTES,
|
||||
withComponentInputBinding()),
|
||||
|
|
Loading…
Reference in New Issue