Merge pull request #629 from adityachandelgit/develop
Merge Develop into Master for release
This commit is contained in:
@@ -6,7 +6,14 @@ export class AuthInitializationService {
|
|||||||
private initialized = new BehaviorSubject<boolean>(false);
|
private initialized = new BehaviorSubject<boolean>(false);
|
||||||
initialized$ = this.initialized.asObservable();
|
initialized$ = this.initialized.asObservable();
|
||||||
|
|
||||||
|
private oidcFailed = new BehaviorSubject<boolean>(false);
|
||||||
|
oidcFailed$ = this.oidcFailed.asObservable();
|
||||||
|
|
||||||
markAsInitialized() {
|
markAsInitialized() {
|
||||||
this.initialized.next(true);
|
this.initialized.next(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setOidcFailed(failed: boolean) {
|
||||||
|
this.oidcFailed.next(failed);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,58 +16,59 @@ export function initializeAuthFactory() {
|
|||||||
|
|
||||||
return new Promise<void>((resolve) => {
|
return new Promise<void>((resolve) => {
|
||||||
const sub = appSettingsService.appSettings$.subscribe(settings => {
|
const sub = appSettingsService.appSettings$.subscribe(settings => {
|
||||||
if (settings) {
|
if (!settings) return;
|
||||||
if (settings.oidcEnabled && settings.oidcProviderDetails) {
|
|
||||||
const details = settings.oidcProviderDetails;
|
|
||||||
|
|
||||||
oauthService.configure({
|
sub.unsubscribe();
|
||||||
issuer: details.issuerUri,
|
|
||||||
clientId: details.clientId,
|
if (settings.oidcEnabled && settings.oidcProviderDetails) {
|
||||||
scope: 'openid profile email offline_access',
|
const details = settings.oidcProviderDetails;
|
||||||
redirectUri: window.location.origin + '/oauth2-callback',
|
|
||||||
responseType: 'code',
|
oauthService.configure({
|
||||||
showDebugInformation: false,
|
issuer: details.issuerUri,
|
||||||
requireHttps: false,
|
clientId: details.clientId,
|
||||||
strictDiscoveryDocumentValidation: false,
|
scope: 'openid profile email offline_access',
|
||||||
|
redirectUri: window.location.origin + '/oauth2-callback',
|
||||||
|
responseType: 'code',
|
||||||
|
showDebugInformation: false,
|
||||||
|
requireHttps: false,
|
||||||
|
strictDiscoveryDocumentValidation: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
oauthService.loadDiscoveryDocumentAndTryLogin()
|
||||||
|
.then(() => {
|
||||||
|
if (oauthService.hasValidAccessToken()) {
|
||||||
|
console.log('[OIDC] Valid access token found');
|
||||||
|
oauthService.setupAutomaticSilentRefresh();
|
||||||
|
websocketInitializer(authService);
|
||||||
|
} else {
|
||||||
|
console.warn('[OIDC] No valid access token. Will proceed to app and show login page.');
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
console.error('[OIDC] Failed to load discovery document or login:', err);
|
||||||
|
authInitService.setOidcFailed(true);
|
||||||
|
})
|
||||||
|
.finally(() => {
|
||||||
|
authInitService.markAsInitialized();
|
||||||
|
resolve();
|
||||||
});
|
});
|
||||||
|
|
||||||
oauthService.loadDiscoveryDocumentAndTryLogin()
|
} else if (settings.remoteAuthEnabled) {
|
||||||
.then(() => {
|
authService.remoteLogin().subscribe({
|
||||||
console.log('[OIDC] Discovery document loaded and login attempted');
|
next: () => {
|
||||||
if (oauthService.hasValidAccessToken()) {
|
authInitService.markAsInitialized();
|
||||||
console.log('[OIDC] Valid access token found after tryLogin');
|
resolve();
|
||||||
router.navigate(['/dashboard']);
|
},
|
||||||
oauthService.setupAutomaticSilentRefresh();
|
error: err => {
|
||||||
websocketInitializer(authService);
|
console.error('[Remote Login] failed:', err);
|
||||||
authInitService.markAsInitialized();
|
authInitService.markAsInitialized();
|
||||||
resolve();
|
resolve();
|
||||||
} else {
|
}
|
||||||
console.log('[OIDC] No valid access token found, attempting silent login with prompt=none');
|
});
|
||||||
oauthService.initCodeFlow();
|
|
||||||
resolve();
|
} else {
|
||||||
}
|
authInitService.markAsInitialized();
|
||||||
})
|
resolve();
|
||||||
.catch(err => {
|
|
||||||
authInitService.markAsInitialized();
|
|
||||||
console.error(
|
|
||||||
'OIDC initialization failed: Unable to complete OpenID Connect discovery or login. ' +
|
|
||||||
'This may be due to an incorrect issuer URL, client ID, or network issue. ' +
|
|
||||||
'Falling back to local login. Details:', err
|
|
||||||
);
|
|
||||||
resolve();
|
|
||||||
});
|
|
||||||
} else if (settings.remoteAuthEnabled) {
|
|
||||||
authService.remoteLogin().subscribe({
|
|
||||||
next: () => {
|
|
||||||
resolve();
|
|
||||||
},
|
|
||||||
error: resolve
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
authInitService.markAsInitialized();
|
|
||||||
resolve();
|
|
||||||
}
|
|
||||||
sub.unsubscribe();
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import {Component, inject, OnInit} from '@angular/core';
|
|||||||
import {Router} from '@angular/router';
|
import {Router} from '@angular/router';
|
||||||
import {OAuthService} from 'angular-oauth2-oidc';
|
import {OAuthService} from 'angular-oauth2-oidc';
|
||||||
import {AuthService} from '../../service/auth.service';
|
import {AuthService} from '../../service/auth.service';
|
||||||
|
import {MessageService} from 'primeng/api';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-oidc-callback',
|
selector: 'app-oidc-callback',
|
||||||
@@ -9,28 +10,29 @@ import {AuthService} from '../../service/auth.service';
|
|||||||
styleUrls: ['./oidc-callback.component.scss']
|
styleUrls: ['./oidc-callback.component.scss']
|
||||||
})
|
})
|
||||||
export class OidcCallbackComponent implements OnInit {
|
export class OidcCallbackComponent implements OnInit {
|
||||||
|
|
||||||
private router = inject(Router);
|
private router = inject(Router);
|
||||||
private oAuthService = inject(OAuthService);
|
private oauthService = inject(OAuthService);
|
||||||
private authService = inject(AuthService);
|
private messageService = inject(MessageService);
|
||||||
|
|
||||||
ngOnInit(): void {
|
async ngOnInit(): Promise<void> {
|
||||||
/*this.oAuthService.tryLoginCodeFlow().then(info => {
|
try {
|
||||||
if (this.oAuthService.hasValidAccessToken()) {
|
await this.oauthService.tryLoginCodeFlow();
|
||||||
const accessToken = this.oAuthService.getAccessToken();
|
if (this.oauthService.hasValidAccessToken()) {
|
||||||
const refreshToken = this.oAuthService.getRefreshToken();
|
|
||||||
this.authService.saveOidcTokens(accessToken, refreshToken ?? '');
|
|
||||||
|
|
||||||
this.authService.getRxStompService().activate();
|
|
||||||
this.oAuthService.setupAutomaticSilentRefresh();
|
|
||||||
this.router.navigate(['/dashboard']);
|
this.router.navigate(['/dashboard']);
|
||||||
} else {
|
} else {
|
||||||
console.error('OIDC code exchange failed');
|
|
||||||
this.router.navigate(['/login']);
|
this.router.navigate(['/login']);
|
||||||
}
|
}
|
||||||
}).catch(err => {
|
} catch (e) {
|
||||||
console.error('OIDC error:', err);
|
console.error('[OIDC Callback] Login failed', e);
|
||||||
this.router.navigate(['/login']);
|
this.messageService.add({
|
||||||
});*/
|
severity: 'error',
|
||||||
|
summary: 'OIDC Login Failed',
|
||||||
|
detail: 'Redirecting to local login...',
|
||||||
|
life: 3000
|
||||||
|
});
|
||||||
|
setTimeout(() => {
|
||||||
|
this.router.navigate(['/login']);
|
||||||
|
}, 3000);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user