fix: restore remote auth
This commit is contained in:
committed by
Aditya Chandel
parent
1d91770656
commit
a904fb7eea
@@ -1,4 +1,5 @@
|
||||
import {inject} from '@angular/core';
|
||||
import {Router} from '@angular/router';
|
||||
import {OAuthEvent, OAuthService} from 'angular-oauth2-oidc';
|
||||
import {AppSettingsService} from './core/service/app-settings.service';
|
||||
import {AuthService, websocketInitializer} from './core/service/auth.service';
|
||||
@@ -9,6 +10,7 @@ export function initializeAuthFactory() {
|
||||
const oauthService = inject(OAuthService);
|
||||
const appSettingsService = inject(AppSettingsService);
|
||||
const authService = inject(AuthService);
|
||||
const router = inject(Router);
|
||||
|
||||
return new Promise<void>((resolve) => {
|
||||
const sub = appSettingsService.appSettings$.subscribe(settings => {
|
||||
@@ -50,6 +52,14 @@ export function initializeAuthFactory() {
|
||||
);
|
||||
resolve();
|
||||
});
|
||||
} else if (settings.remoteAuthEnabled) {
|
||||
authService.remoteLogin().subscribe({
|
||||
next: () => {
|
||||
router.navigate(['/dashboard']);
|
||||
resolve();
|
||||
},
|
||||
error: resolve
|
||||
});
|
||||
} else {
|
||||
resolve();
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ export interface AppSettings {
|
||||
coverResolution: string;
|
||||
uploadPattern: string;
|
||||
opdsServerEnabled: boolean;
|
||||
remoteAuthEnabled: boolean;
|
||||
oidcEnabled: boolean;
|
||||
oidcProviderDetails: OidcProviderDetails;
|
||||
oidcAutoProvisionDetails: OidcAutoProvisionDetails;
|
||||
|
||||
@@ -16,8 +16,8 @@ export class AuthService {
|
||||
private http = inject(HttpClient);
|
||||
private injector = inject(Injector);
|
||||
|
||||
internalLogin(credentials: { username: string; password: string }): Observable<any> {
|
||||
return this.http.post<{ accessToken: string; refreshToken: string }>(`${this.apiUrl}/login`, credentials).pipe(
|
||||
internalLogin(credentials: { username: string; password: string }): Observable<{ accessToken: string; refreshToken: string, isDefaultPassword: string }> {
|
||||
return this.http.post<{ accessToken: string; refreshToken: string, isDefaultPassword: string }>(`${this.apiUrl}/login`, credentials).pipe(
|
||||
tap((response) => {
|
||||
if (response.accessToken && response.refreshToken) {
|
||||
this.saveInternalTokens(response.accessToken, response.refreshToken);
|
||||
@@ -38,6 +38,17 @@ export class AuthService {
|
||||
);
|
||||
}
|
||||
|
||||
remoteLogin(): Observable<{ accessToken: string; refreshToken: string, isDefaultPassword: string }> {
|
||||
return this.http.get<{ accessToken: string; refreshToken: string, isDefaultPassword: string }>(`${this.apiUrl}/remote`).pipe(
|
||||
tap((response) => {
|
||||
if (response.accessToken && response.refreshToken) {
|
||||
this.saveInternalTokens(response.accessToken, response.refreshToken);
|
||||
this.initializeWebSocketConnection();
|
||||
}
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
saveInternalTokens(accessToken: string, refreshToken: string): void {
|
||||
localStorage.setItem('accessToken_Internal', accessToken);
|
||||
localStorage.setItem('refreshToken_Internal', refreshToken);
|
||||
|
||||
Reference in New Issue
Block a user