* overhaul OIDC: backend token exchange, security hardening, group mapping, session management * add unit tests for OIDC overhaul (166 tests across 12 classes) * rewrite unit tests for metadata and extractor packages (~450 tests) * fix Kobo sync timeout with large magic shelves (#3172)
This commit is contained in:
@@ -17,121 +17,94 @@
|
||||
<p class="login-subtitle">{{ t('subtitle') }}</p>
|
||||
</div>
|
||||
|
||||
@if (showOidcBypassInfo) {
|
||||
<div class="oidc-warning">
|
||||
<div class="warning-content">
|
||||
<div class="warning-header">
|
||||
<i class="pi pi-exclamation-triangle"></i>
|
||||
<span>{{ t('oidcWarningTitle') }}</span>
|
||||
</div>
|
||||
<p class="warning-message">{{ oidcBypassMessage }}</p>
|
||||
<div class="warning-actions">
|
||||
<p-button
|
||||
size="small"
|
||||
severity="warn"
|
||||
[label]="t('retryOidc')"
|
||||
icon="pi pi-refresh"
|
||||
(click)="retryOidc()"
|
||||
/>
|
||||
<p-button
|
||||
size="small"
|
||||
severity="success"
|
||||
[label]="t('useLocalLogin')"
|
||||
icon="pi pi-times"
|
||||
(click)="dismissOidcWarning()"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
@if (infoMessage) {
|
||||
<div class="info-message" style="margin-bottom: 1rem;">
|
||||
<p-message severity="info">{{ infoMessage }}</p-message>
|
||||
</div>
|
||||
}
|
||||
|
||||
<form class="login-form" #loginForm="ngForm" (ngSubmit)="login()">
|
||||
<div class="form-field">
|
||||
<label for="username" class="form-label">
|
||||
<i class="pi pi-user"></i>
|
||||
<span>{{ t('usernameLabel') }}</span>
|
||||
</label>
|
||||
<input
|
||||
fluid
|
||||
pInputText
|
||||
id="username"
|
||||
name="username"
|
||||
required
|
||||
[(ngModel)]="username"
|
||||
[placeholder]="t('usernamePlaceholder')"
|
||||
class="form-input"
|
||||
autocomplete="username"
|
||||
/>
|
||||
@if (errorMessage) {
|
||||
<div class="error-message" style="margin-bottom: 1rem;">
|
||||
<p-message severity="error">{{ errorMessage }}</p-message>
|
||||
</div>
|
||||
}
|
||||
|
||||
<div class="form-field">
|
||||
<label for="password" class="form-label">
|
||||
<i class="pi pi-lock"></i>
|
||||
<span>{{ t('passwordLabel') }}</span>
|
||||
</label>
|
||||
<p-password
|
||||
id="password"
|
||||
name="password"
|
||||
required
|
||||
[(ngModel)]="password"
|
||||
[feedback]="false"
|
||||
[placeholder]="t('passwordPlaceholder')"
|
||||
[toggleMask]="true"
|
||||
[fluid]="true"
|
||||
autocomplete="current-password"
|
||||
></p-password>
|
||||
</div>
|
||||
|
||||
<p-button
|
||||
fluid
|
||||
type="submit"
|
||||
[label]="t('signIn')"
|
||||
icon="pi pi-sign-in"
|
||||
[disabled]="!loginForm.valid || !username || !password"
|
||||
class="login-button">
|
||||
</p-button>
|
||||
|
||||
@if (errorMessage) {
|
||||
<div class="error-message">
|
||||
<p-message severity="error">{{ errorMessage }}</p-message>
|
||||
@if (showLocalLogin) {
|
||||
<form class="login-form" #loginForm="ngForm" (ngSubmit)="login()">
|
||||
<div class="form-field">
|
||||
<label for="username" class="form-label">
|
||||
<i class="pi pi-user"></i>
|
||||
<span>{{ t('usernameLabel') }}</span>
|
||||
</label>
|
||||
<input
|
||||
fluid
|
||||
pInputText
|
||||
id="username"
|
||||
name="username"
|
||||
required
|
||||
[(ngModel)]="username"
|
||||
[placeholder]="t('usernamePlaceholder')"
|
||||
class="form-input"
|
||||
autocomplete="username"
|
||||
/>
|
||||
</div>
|
||||
}
|
||||
|
||||
@if (oidcEnabled && !isOidcBypassed) {
|
||||
<div class="divider">
|
||||
<span>{{ t('orContinueWith') }}</span>
|
||||
<div class="form-field">
|
||||
<label for="password" class="form-label">
|
||||
<i class="pi pi-lock"></i>
|
||||
<span>{{ t('passwordLabel') }}</span>
|
||||
</label>
|
||||
<p-password
|
||||
id="password"
|
||||
name="password"
|
||||
required
|
||||
[(ngModel)]="password"
|
||||
[feedback]="false"
|
||||
[placeholder]="t('passwordPlaceholder')"
|
||||
[toggleMask]="true"
|
||||
[fluid]="true"
|
||||
autocomplete="current-password"
|
||||
></p-password>
|
||||
</div>
|
||||
|
||||
<p-button
|
||||
fluid
|
||||
severity="secondary"
|
||||
[label]="isOidcLoginInProgress ? t('redirectingTo', {provider: oidcName}) : oidcName"
|
||||
[icon]="isOidcLoginInProgress ? 'pi pi-spin pi-spinner' : 'pi pi-id-card'"
|
||||
[disabled]="isOidcLoginInProgress"
|
||||
(click)="loginWithOidc()"
|
||||
class="oidc-button"/>
|
||||
type="submit"
|
||||
[label]="t('signIn')"
|
||||
icon="pi pi-sign-in"
|
||||
[disabled]="!loginForm.valid || !username || !password"
|
||||
class="login-button">
|
||||
</p-button>
|
||||
|
||||
<div class="help-text">
|
||||
<button
|
||||
type="button"
|
||||
class="text-link"
|
||||
(click)="bypassOidc()">
|
||||
{{ t('oidcTrouble', {provider: oidcName}) }}
|
||||
</button>
|
||||
@if (oidcEnabled) {
|
||||
<div class="divider">
|
||||
<span>{{ t('orContinueWith') }}</span>
|
||||
</div>
|
||||
|
||||
<p-button
|
||||
fluid
|
||||
severity="secondary"
|
||||
[label]="isOidcLoginInProgress ? t('redirectingTo', {provider: oidcName}) : oidcName"
|
||||
[icon]="isOidcLoginInProgress ? 'pi pi-spin pi-spinner' : 'pi pi-id-card'"
|
||||
[disabled]="isOidcLoginInProgress"
|
||||
(click)="loginWithOidc()"
|
||||
class="oidc-button"/>
|
||||
}
|
||||
</form>
|
||||
} @else {
|
||||
@if (oidcEnabled) {
|
||||
<div class="login-form">
|
||||
<p-button
|
||||
fluid
|
||||
severity="secondary"
|
||||
[label]="isOidcLoginInProgress ? t('redirectingTo', {provider: oidcName}) : oidcName"
|
||||
[icon]="isOidcLoginInProgress ? 'pi pi-spin pi-spinner' : 'pi pi-id-card'"
|
||||
[disabled]="isOidcLoginInProgress"
|
||||
(click)="loginWithOidc()"
|
||||
class="oidc-button"/>
|
||||
</div>
|
||||
}
|
||||
|
||||
@if (oidcEnabled && isOidcBypassed) {
|
||||
<div class="help-text">
|
||||
<button
|
||||
type="button"
|
||||
class="text-link primary"
|
||||
(click)="enableOidc()">
|
||||
{{ t('reEnableOidc', {provider: oidcName}) }}
|
||||
</button>
|
||||
</div>
|
||||
}
|
||||
</form>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,17 +1,16 @@
|
||||
import {Component, inject, OnDestroy, OnInit} from '@angular/core';
|
||||
import {Component, inject, OnInit} from '@angular/core';
|
||||
import {AuthService} from '../../service/auth.service';
|
||||
import {Router} from '@angular/router';
|
||||
import {ActivatedRoute, Router} from '@angular/router';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {Password} from 'primeng/password';
|
||||
import {Button} from 'primeng/button';
|
||||
import {Message} from 'primeng/message';
|
||||
import {InputText} from 'primeng/inputtext';
|
||||
import {OAuthService} from 'angular-oauth2-oidc';
|
||||
import {Observable, Subject} from 'rxjs';
|
||||
import {Observable} from 'rxjs';
|
||||
import {filter, take} from 'rxjs/operators';
|
||||
import {getOidcErrorCount, isOidcBypassed, resetOidcBypass} from '../../../core/security/auth-initializer';
|
||||
import {AppSettingsService, PublicAppSettings} from '../../service/app-settings.service';
|
||||
import {TranslocoDirective, TranslocoService} from '@jsverse/transloco';
|
||||
import {OidcService} from '../../../core/security/oidc.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-login',
|
||||
@@ -26,28 +25,46 @@ import {TranslocoDirective, TranslocoService} from '@jsverse/transloco';
|
||||
templateUrl: './login.component.html',
|
||||
styleUrls: ['./login.component.scss']
|
||||
})
|
||||
export class LoginComponent implements OnInit, OnDestroy {
|
||||
export class LoginComponent implements OnInit {
|
||||
username = '';
|
||||
password = '';
|
||||
errorMessage = '';
|
||||
infoMessage = '';
|
||||
oidcEnabled = false;
|
||||
oidcName = 'OIDC';
|
||||
isOidcBypassed = false;
|
||||
showOidcBypassInfo = false;
|
||||
oidcBypassMessage = '';
|
||||
isOidcLoginInProgress = false;
|
||||
showLocalLogin = true;
|
||||
private oidcOnlyAutoRedirect = false;
|
||||
|
||||
private authService = inject(AuthService);
|
||||
private oAuthService = inject(OAuthService);
|
||||
private oidcService = inject(OidcService);
|
||||
private appSettingsService = inject(AppSettingsService);
|
||||
private router = inject(Router);
|
||||
private route = inject(ActivatedRoute);
|
||||
private translocoService = inject(TranslocoService);
|
||||
|
||||
publicAppSettings$: Observable<PublicAppSettings | null> = this.appSettingsService.publicAppSettings$;
|
||||
|
||||
private destroy$ = new Subject<void>();
|
||||
private static readonly OIDC_ERROR_KEYS: Record<string, string> = {
|
||||
'state_mismatch': 'auth.login.oidcErrors.stateMismatch',
|
||||
'missing_code': 'auth.login.oidcErrors.stateMismatch',
|
||||
'exchange_failed': 'auth.login.oidcErrors.exchangeFailed'
|
||||
};
|
||||
|
||||
private static readonly MAX_REDIRECT_COUNT = 3;
|
||||
|
||||
ngOnInit(): void {
|
||||
this.route.queryParams.pipe(take(1)).subscribe(params => {
|
||||
if (params['reason'] === 'session_revoked') {
|
||||
this.infoMessage = this.translocoService.translate('auth.login.sessionRevoked');
|
||||
}
|
||||
|
||||
const oidcError = params['oidcError'];
|
||||
if (oidcError) {
|
||||
this.errorMessage = this.resolveOidcError(oidcError);
|
||||
}
|
||||
});
|
||||
|
||||
this.publicAppSettings$
|
||||
.pipe(
|
||||
filter(settings => settings != null),
|
||||
@@ -56,25 +73,55 @@ export class LoginComponent implements OnInit, OnDestroy {
|
||||
.subscribe(publicSettings => {
|
||||
this.oidcEnabled = publicSettings!.oidcEnabled;
|
||||
this.oidcName = publicSettings!.oidcProviderDetails?.providerName || 'OIDC';
|
||||
this.checkOidcBypassStatus();
|
||||
|
||||
this.route.queryParams.pipe(take(1)).subscribe(params => {
|
||||
const isLocalMode = params['local'] === 'true';
|
||||
const hasOidcError = !!params['oidcError'];
|
||||
|
||||
if (publicSettings!.oidcForceOnlyMode && !isLocalMode && !hasOidcError) {
|
||||
this.handleAutoRedirect();
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
private checkOidcBypassStatus(): void {
|
||||
this.isOidcBypassed = isOidcBypassed();
|
||||
const errorCount = getOidcErrorCount();
|
||||
private handleAutoRedirect(): void {
|
||||
const countStr = sessionStorage.getItem('oidc_redirect_count');
|
||||
const count = countStr ? parseInt(countStr, 10) : 0;
|
||||
|
||||
if (this.oidcEnabled && (this.isOidcBypassed || errorCount > 0)) {
|
||||
this.showOidcBypassInfo = true;
|
||||
|
||||
if (this.isOidcBypassed && errorCount >= 3) {
|
||||
this.oidcBypassMessage = this.translocoService.translate('auth.login.oidcAutoDisabled', {provider: this.oidcName, count: errorCount});
|
||||
} else if (this.isOidcBypassed) {
|
||||
this.oidcBypassMessage = this.translocoService.translate('auth.login.oidcManuallyDisabled', {provider: this.oidcName});
|
||||
} else if (errorCount > 0) {
|
||||
this.oidcBypassMessage = this.translocoService.translate('auth.login.oidcErrors', {provider: this.oidcName, count: errorCount});
|
||||
}
|
||||
if (count >= LoginComponent.MAX_REDIRECT_COUNT) {
|
||||
sessionStorage.removeItem('oidc_redirect_count');
|
||||
this.errorMessage = this.translocoService.translate('auth.login.oidcOnlyRedirectFailed');
|
||||
this.showLocalLogin = false;
|
||||
return;
|
||||
}
|
||||
|
||||
this.oidcOnlyAutoRedirect = true;
|
||||
sessionStorage.setItem('oidc_redirect_count', String(count + 1));
|
||||
this.showLocalLogin = false;
|
||||
this.loginWithOidc();
|
||||
}
|
||||
|
||||
private resolveOidcError(error: string): string {
|
||||
if (error.startsWith('OIDC user')) {
|
||||
return this.translocoService.translate('auth.login.oidcErrors.userNotProvisioned');
|
||||
}
|
||||
if (error.startsWith('Cannot reach')) {
|
||||
return this.translocoService.translate('auth.login.oidcErrors.providerUnreachable');
|
||||
}
|
||||
if (error.startsWith('Invalid token') || error.startsWith('No token')) {
|
||||
return this.translocoService.translate('auth.login.oidcErrors.invalidToken');
|
||||
}
|
||||
if (error.startsWith('Failed to exchange') || error.includes('token exchange')) {
|
||||
return this.translocoService.translate('auth.login.oidcErrors.exchangeFailed');
|
||||
}
|
||||
|
||||
const key = LoginComponent.OIDC_ERROR_KEYS[error];
|
||||
if (key) {
|
||||
return this.translocoService.translate(key);
|
||||
}
|
||||
|
||||
return this.translocoService.translate('auth.login.oidcErrors.unknown');
|
||||
}
|
||||
|
||||
login(): void {
|
||||
@@ -98,7 +145,7 @@ export class LoginComponent implements OnInit, OnDestroy {
|
||||
});
|
||||
}
|
||||
|
||||
loginWithOidc(): void {
|
||||
async loginWithOidc(): Promise<void> {
|
||||
if (this.isOidcLoginInProgress) {
|
||||
return;
|
||||
}
|
||||
@@ -107,45 +154,36 @@ export class LoginComponent implements OnInit, OnDestroy {
|
||||
this.errorMessage = '';
|
||||
|
||||
try {
|
||||
setTimeout(() => {
|
||||
const publicSettings = this.appSettingsService.currentPublicSettings;
|
||||
if (!publicSettings?.oidcProviderDetails) {
|
||||
this.errorMessage = this.translocoService.translate('auth.login.oidcInitError');
|
||||
this.isOidcLoginInProgress = false;
|
||||
}, 5000);
|
||||
this.oAuthService.initCodeFlow();
|
||||
return;
|
||||
}
|
||||
|
||||
const details = publicSettings.oidcProviderDetails;
|
||||
const pkce = await this.oidcService.generatePkce();
|
||||
const state = await this.oidcService.fetchState();
|
||||
const nonce = this.oidcService.generateRandomString();
|
||||
|
||||
this.oidcService.storePkceState({codeVerifier: pkce.codeVerifier, state, nonce});
|
||||
|
||||
const authUrl = await this.oidcService.buildAuthUrl(
|
||||
details.issuerUri,
|
||||
details.clientId,
|
||||
pkce.codeChallenge,
|
||||
state,
|
||||
nonce
|
||||
);
|
||||
|
||||
window.location.href = authUrl;
|
||||
} catch (error) {
|
||||
console.error('OIDC login initiation failed:', error);
|
||||
this.errorMessage = this.translocoService.translate('auth.login.oidcInitError');
|
||||
sessionStorage.removeItem('oidc_redirect_count');
|
||||
this.errorMessage = this.translocoService.translate('auth.login.oidcErrors.providerUnreachable');
|
||||
this.showLocalLogin = !this.oidcOnlyAutoRedirect;
|
||||
this.isOidcLoginInProgress = false;
|
||||
}
|
||||
}
|
||||
|
||||
bypassOidc(): void {
|
||||
localStorage.setItem('booklore-oidc-bypass', 'true');
|
||||
this.isOidcBypassed = true;
|
||||
this.showOidcBypassInfo = false;
|
||||
}
|
||||
|
||||
enableOidc(): void {
|
||||
resetOidcBypass();
|
||||
this.isOidcBypassed = false;
|
||||
this.showOidcBypassInfo = false;
|
||||
this.isOidcLoginInProgress = false;
|
||||
window.location.reload();
|
||||
}
|
||||
|
||||
retryOidc(): void {
|
||||
resetOidcBypass();
|
||||
this.isOidcBypassed = false;
|
||||
this.showOidcBypassInfo = false;
|
||||
this.isOidcLoginInProgress = false;
|
||||
window.location.reload();
|
||||
}
|
||||
|
||||
dismissOidcWarning(): void {
|
||||
this.showOidcBypassInfo = false;
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
this.destroy$.next();
|
||||
this.destroy$.complete();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,16 +33,19 @@ export interface MetadataMatchWeights {
|
||||
export interface OidcProviderDetails {
|
||||
providerName: string;
|
||||
clientId: string;
|
||||
clientSecret?: string;
|
||||
issuerUri: string;
|
||||
claimMapping: {
|
||||
username: string;
|
||||
email: string;
|
||||
name: string;
|
||||
groups: string;
|
||||
};
|
||||
}
|
||||
|
||||
export interface OidcAutoProvisionDetails {
|
||||
enableAutoProvisioning: boolean;
|
||||
allowLocalAccountLinking: boolean;
|
||||
defaultPermissions: string[];
|
||||
defaultLibraryIds: number[];
|
||||
}
|
||||
@@ -156,6 +159,17 @@ export interface CoverCroppingSettings {
|
||||
smartCroppingEnabled: boolean;
|
||||
}
|
||||
|
||||
export interface OidcTestCheck {
|
||||
name: string;
|
||||
status: 'PASS' | 'FAIL' | 'WARN' | 'SKIP';
|
||||
message: string;
|
||||
}
|
||||
|
||||
export interface OidcTestResult {
|
||||
success: boolean;
|
||||
checks: OidcTestCheck[];
|
||||
}
|
||||
|
||||
export interface AppSettings {
|
||||
autoBookSearch: boolean;
|
||||
similarBookRecommendation: boolean;
|
||||
@@ -179,6 +193,9 @@ export interface AppSettings {
|
||||
metadataDownloadOnBookdrop: boolean;
|
||||
telemetryEnabled: boolean;
|
||||
metadataProviderSpecificFields: MetadataProviderSpecificFields;
|
||||
oidcSessionDurationHours: number | null;
|
||||
oidcGroupSyncMode: string | null;
|
||||
oidcForceOnlyMode: boolean;
|
||||
diskType: string;
|
||||
}
|
||||
|
||||
@@ -226,4 +243,7 @@ export enum AppSettingKey {
|
||||
COVER_CROPPING_SETTINGS = 'COVER_CROPPING_SETTINGS',
|
||||
TELEMETRY_ENABLED = 'TELEMETRY_ENABLED',
|
||||
METADATA_PROVIDER_SPECIFIC_FIELDS = 'METADATA_PROVIDER_SPECIFIC_FIELDS',
|
||||
OIDC_SESSION_DURATION_HOURS = 'OIDC_SESSION_DURATION_HOURS',
|
||||
OIDC_GROUP_SYNC_MODE = 'OIDC_GROUP_SYNC_MODE',
|
||||
OIDC_FORCE_ONLY_MODE = 'OIDC_FORCE_ONLY_MODE',
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
export interface OidcGroupMapping {
|
||||
id?: number;
|
||||
oidcGroupClaim: string;
|
||||
isAdmin: boolean;
|
||||
permissions: string[];
|
||||
libraryIds: number[];
|
||||
description: string;
|
||||
}
|
||||
@@ -1,21 +1,20 @@
|
||||
import {inject, Injectable, Injector} from '@angular/core';
|
||||
import {inject, Injectable} from '@angular/core';
|
||||
import {HttpClient} from '@angular/common/http';
|
||||
import {BehaviorSubject, Observable, of} from 'rxjs';
|
||||
import {catchError, finalize, map, shareReplay, switchMap, tap} from 'rxjs/operators';
|
||||
import {API_CONFIG} from '../../core/config/api-config';
|
||||
import {AppSettings, OidcProviderDetails} from '../model/app-settings.model';
|
||||
import {AuthService} from './auth.service';
|
||||
import {AppSettings, OidcProviderDetails, OidcTestResult} from '../model/app-settings.model';
|
||||
|
||||
export interface PublicAppSettings {
|
||||
oidcEnabled: boolean;
|
||||
remoteAuthEnabled: boolean;
|
||||
oidcProviderDetails: OidcProviderDetails;
|
||||
oidcForceOnlyMode: boolean;
|
||||
}
|
||||
|
||||
@Injectable({providedIn: 'root'})
|
||||
export class AppSettingsService {
|
||||
private http = inject(HttpClient);
|
||||
private injector = inject(Injector);
|
||||
|
||||
private readonly apiUrl = `${API_CONFIG.BASE_URL}/api/v1/settings`;
|
||||
private readonly publicApiUrl = `${API_CONFIG.BASE_URL}/api/v1/public-settings`;
|
||||
@@ -50,6 +49,10 @@ export class AppSettingsService {
|
||||
})
|
||||
);
|
||||
|
||||
get currentPublicSettings(): PublicAppSettings | null {
|
||||
return this.publicAppSettingsSubject.value;
|
||||
}
|
||||
|
||||
private fetchAppSettings(): Observable<AppSettings> {
|
||||
return this.http.get<AppSettings>(this.apiUrl).pipe(
|
||||
tap(settings => {
|
||||
@@ -74,11 +77,16 @@ export class AppSettingsService {
|
||||
);
|
||||
}
|
||||
|
||||
testOidcConnection(providerDetails: OidcProviderDetails): Observable<OidcTestResult> {
|
||||
return this.http.post<OidcTestResult>(`${this.apiUrl}/oidc/test`, providerDetails);
|
||||
}
|
||||
|
||||
private syncPublicSettings(appSettings: AppSettings): void {
|
||||
const updatedPublicSettings: PublicAppSettings = {
|
||||
oidcEnabled: appSettings.oidcEnabled,
|
||||
remoteAuthEnabled: appSettings.remoteAuthEnabled,
|
||||
oidcProviderDetails: appSettings.oidcProviderDetails
|
||||
oidcProviderDetails: appSettings.oidcProviderDetails,
|
||||
oidcForceOnlyMode: appSettings.oidcForceOnlyMode
|
||||
};
|
||||
const current = this.publicAppSettingsSubject.value;
|
||||
|
||||
@@ -86,6 +94,7 @@ export class AppSettingsService {
|
||||
!current ||
|
||||
current.oidcEnabled !== updatedPublicSettings.oidcEnabled ||
|
||||
current.remoteAuthEnabled !== updatedPublicSettings.remoteAuthEnabled ||
|
||||
current.oidcForceOnlyMode !== updatedPublicSettings.oidcForceOnlyMode ||
|
||||
JSON.stringify(current.oidcProviderDetails) !== JSON.stringify(updatedPublicSettings.oidcProviderDetails)
|
||||
) {
|
||||
this.publicAppSettingsSubject.next(updatedPublicSettings);
|
||||
@@ -118,12 +127,6 @@ export class AppSettingsService {
|
||||
this.appSettingsSubject.next({...current});
|
||||
this.syncPublicSettings(current);
|
||||
}
|
||||
if (!enabled) {
|
||||
const authService = this.injector.get(AuthService);
|
||||
setTimeout(() => {
|
||||
authService.clearOIDCTokens();
|
||||
});
|
||||
}
|
||||
}),
|
||||
catchError(err => {
|
||||
console.error('Error toggling OIDC:', err);
|
||||
|
||||
@@ -4,7 +4,6 @@ import {BehaviorSubject, Observable, tap} from 'rxjs';
|
||||
import {RxStompService} from '../websocket/rx-stomp.service';
|
||||
import {API_CONFIG} from '../../core/config/api-config';
|
||||
import {createRxStompConfig} from '../websocket/rx-stomp.config';
|
||||
import {OAuthService, OAuthStorage} from 'angular-oauth2-oidc';
|
||||
import {Router} from '@angular/router';
|
||||
import {PostLoginInitializerService} from '../../core/services/post-login-initializer.service';
|
||||
|
||||
@@ -19,12 +18,10 @@ export class AuthService {
|
||||
|
||||
private http = inject(HttpClient);
|
||||
private injector = inject(Injector);
|
||||
private oAuthService = inject(OAuthService);
|
||||
private oAuthStorage = inject(OAuthStorage);
|
||||
private router = inject(Router);
|
||||
private postLoginInitializer = inject(PostLoginInitializerService);
|
||||
|
||||
public tokenSubject = new BehaviorSubject<string | null>(this.getOidcAccessToken() || this.getInternalAccessToken());
|
||||
public tokenSubject = new BehaviorSubject<string | null>(this.getInternalAccessToken());
|
||||
public token$ = this.tokenSubject.asObservable();
|
||||
|
||||
internalLogin(credentials: { username: string; password: string }): Observable<{ accessToken: string; refreshToken: string, isDefaultPassword: string }> {
|
||||
@@ -72,36 +69,39 @@ export class AuthService {
|
||||
return localStorage.getItem('accessToken_Internal');
|
||||
}
|
||||
|
||||
getOidcAccessToken(): string | null {
|
||||
return this.oAuthService.getIdToken();
|
||||
}
|
||||
|
||||
getInternalRefreshToken(): string | null {
|
||||
return localStorage.getItem('refreshToken_Internal');
|
||||
}
|
||||
|
||||
clearOIDCTokens(): void {
|
||||
const hasInternalTokens = this.getInternalAccessToken() || this.getInternalRefreshToken();
|
||||
if (!hasInternalTokens) {
|
||||
this.oAuthStorage.removeItem("access_token");
|
||||
this.oAuthStorage.removeItem("refresh_token");
|
||||
this.oAuthStorage.removeItem("id_token");
|
||||
this.router.navigate(['/login']);
|
||||
}
|
||||
logout(): void {
|
||||
const refreshToken = this.getInternalRefreshToken();
|
||||
this.http.post<{ logoutUrl: string | null }>(`${this.apiUrl}/logout`, {refreshToken}).subscribe({
|
||||
next: (response) => {
|
||||
this.clearSession();
|
||||
if (response.logoutUrl) {
|
||||
window.location.href = response.logoutUrl;
|
||||
} else {
|
||||
this.router.navigate(['/login']).then(() => window.location.reload());
|
||||
}
|
||||
},
|
||||
error: () => {
|
||||
this.clearSession();
|
||||
this.router.navigate(['/login']).then(() => window.location.reload());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
logout(): void {
|
||||
forceLogout(reason: string): void {
|
||||
this.clearSession();
|
||||
this.router.navigate(['/login'], {queryParams: {reason}});
|
||||
}
|
||||
|
||||
private clearSession(): void {
|
||||
localStorage.removeItem('accessToken_Internal');
|
||||
localStorage.removeItem('refreshToken_Internal');
|
||||
this.oAuthStorage.removeItem("access_token");
|
||||
this.oAuthStorage.removeItem("refresh_token");
|
||||
this.oAuthStorage.removeItem("id_token");
|
||||
this.tokenSubject.next(null);
|
||||
this.postLoginInitialized = false;
|
||||
this.getRxStompService().deactivate();
|
||||
this.router.navigate(['/login']).then(() => {
|
||||
window.location.reload();
|
||||
});
|
||||
}
|
||||
|
||||
getRxStompService(): RxStompService {
|
||||
@@ -112,7 +112,7 @@ export class AuthService {
|
||||
}
|
||||
|
||||
initializeWebSocketConnection(): void {
|
||||
const token = this.getOidcAccessToken() || this.getInternalAccessToken();
|
||||
const token = this.getInternalAccessToken();
|
||||
if (!token) return;
|
||||
|
||||
const stompService = this.getRxStompService();
|
||||
|
||||
@@ -68,7 +68,7 @@ export class CustomFontService {
|
||||
}
|
||||
|
||||
private getToken(): string | null {
|
||||
return this.authService.getOidcAccessToken() || this.authService.getInternalAccessToken();
|
||||
return this.authService.getInternalAccessToken();
|
||||
}
|
||||
|
||||
public appendToken(url: string): string {
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
import {inject, Injectable} from '@angular/core';
|
||||
import {HttpClient} from '@angular/common/http';
|
||||
import {Observable} from 'rxjs';
|
||||
import {OidcGroupMapping} from '../model/oidc-group-mapping.model';
|
||||
import {API_CONFIG} from '../../core/config/api-config';
|
||||
|
||||
@Injectable({providedIn: 'root'})
|
||||
export class OidcGroupMappingService {
|
||||
|
||||
private http = inject(HttpClient);
|
||||
private baseUrl = `${API_CONFIG.BASE_URL}/api/v1/admin/oidc-group-mappings`;
|
||||
|
||||
getAll(): Observable<OidcGroupMapping[]> {
|
||||
return this.http.get<OidcGroupMapping[]>(this.baseUrl);
|
||||
}
|
||||
|
||||
create(mapping: OidcGroupMapping): Observable<OidcGroupMapping> {
|
||||
return this.http.post<OidcGroupMapping>(this.baseUrl, mapping);
|
||||
}
|
||||
|
||||
update(id: number, mapping: OidcGroupMapping): Observable<OidcGroupMapping> {
|
||||
return this.http.put<OidcGroupMapping>(`${this.baseUrl}/${id}`, mapping);
|
||||
}
|
||||
|
||||
delete(id: number): Observable<void> {
|
||||
return this.http.delete<void>(`${this.baseUrl}/${id}`);
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,6 @@ import {AuthService} from './auth.service';
|
||||
import {UserService} from '../../features/settings/user-management/user.service';
|
||||
import {filter, catchError} from 'rxjs/operators';
|
||||
import {of} from 'rxjs';
|
||||
import {OAuthService} from 'angular-oauth2-oidc';
|
||||
|
||||
@Injectable({providedIn: 'root'})
|
||||
export class StartupService {
|
||||
|
||||
@@ -17,7 +17,7 @@ export class UrlHelperService {
|
||||
private router = inject(Router);
|
||||
|
||||
private getToken(): string | null {
|
||||
return this.authService.getOidcAccessToken() || this.authService.getInternalAccessToken();
|
||||
return this.authService.getInternalAccessToken();
|
||||
}
|
||||
|
||||
private appendToken(url: string): string {
|
||||
|
||||
@@ -9,9 +9,7 @@ export function createRxStompConfig(authService: AuthService): RxStompConfig {
|
||||
heartbeatOutgoing: 20000,
|
||||
reconnectDelay: 10000,
|
||||
beforeConnect: (stomp) => {
|
||||
const oidcToken = authService.getOidcAccessToken();
|
||||
const internalToken = authService.getInternalAccessToken();
|
||||
const token = oidcToken || internalToken;
|
||||
const token = authService.getInternalAccessToken();
|
||||
if (token) {
|
||||
stomp.stompClient.connectHeaders = {
|
||||
'Authorization': `Bearer ${token}`,
|
||||
|
||||
Reference in New Issue
Block a user