Fix Kobo sync timeout with large magic shelves (#3172) (#3173)

* 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:
ACX
2026-03-04 15:11:20 -07:00
committed by GitHub
parent f8375f03f3
commit 3ff8f0f69f
148 changed files with 18941 additions and 8047 deletions
@@ -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 {