This commit is contained in:
2026-05-24 09:27:01 +02:00
parent e946436a42
commit 14156a23fb
9 changed files with 154 additions and 150 deletions
+18
View File
@@ -0,0 +1,18 @@
import { HttpInterceptorFn } from '@angular/common/http';
import { inject } from '@angular/core';
import { from, switchMap } from 'rxjs';
import { KeycloakService } from './keycloak.service';
import { API_BASE_URL } from '../issues/issues-api.service';
export const authInterceptor: HttpInterceptorFn = (req, next) => {
if (!req.url.startsWith(API_BASE_URL)) {
return next(req);
}
const keycloak = inject(KeycloakService);
return from(keycloak.getToken()).pipe(
switchMap((token) => {
if (!token) return next(req);
return next(req.clone({ setHeaders: { Authorization: `Bearer ${token}` } }));
}),
);
};
+9
View File
@@ -38,4 +38,13 @@ export class KeycloakService {
isLoggedIn(): boolean {
return this.keycloak.authenticated ?? false;
}
async getToken(): Promise<string | undefined> {
try {
await this.keycloak.updateToken(30);
return this.keycloak.token;
} catch {
return undefined;
}
}
}