WEB-233: Improve the OIDC integration with 2FA (#2602)
This commit is contained in:
@@ -105,15 +105,12 @@ export class AuthenticationService {
|
||||
httpParams = httpParams.set('grant_type', 'password');
|
||||
let headers = new HttpHeaders();
|
||||
headers = headers.set('Content-Type', 'application/x-www-form-urlencoded');
|
||||
return this.http
|
||||
.disableApiPrefix()
|
||||
.post(`${environment.oauth.serverUrl}/token`, httpParams.toString(), { headers: headers })
|
||||
.pipe(
|
||||
map((tokenResponse: OAuth2Token) => {
|
||||
this.getUserDetails(tokenResponse);
|
||||
return of(true);
|
||||
})
|
||||
);
|
||||
return this.http.post(`${environment.oauth.serverUrl}/token`, httpParams.toString(), { headers: headers }).pipe(
|
||||
map((tokenResponse: OAuth2Token) => {
|
||||
this.getUserDetails(tokenResponse);
|
||||
return of(true);
|
||||
})
|
||||
);
|
||||
} else {
|
||||
return this.http
|
||||
.post('/authentication', { username: loginContext.username, password: loginContext.password })
|
||||
@@ -137,7 +134,6 @@ export class AuthenticationService {
|
||||
let headers = new HttpHeaders();
|
||||
headers = headers.set('Authorization', 'bearer ' + tokenResponse.access_token);
|
||||
this.http
|
||||
.disableApiPrefix()
|
||||
.get(`${environment.serverUrl}/userdetails`, { headers: headers })
|
||||
.subscribe((credentials: Credentials) => {
|
||||
this.onLoginSuccess(credentials);
|
||||
@@ -174,7 +170,6 @@ export class AuthenticationService {
|
||||
let headers = new HttpHeaders();
|
||||
headers = headers.set('Content-Type', 'application/x-www-form-urlencoded');
|
||||
return this.http
|
||||
.disableApiPrefix()
|
||||
.post(`${environment.oauth.serverUrl}/token`, httpParams.toString(), { headers: headers })
|
||||
.subscribe((tokenResponse: OAuth2Token) => {
|
||||
this.storage.setItem(this.oAuthTokenDetailsStorageKey, JSON.stringify(tokenResponse));
|
||||
@@ -241,7 +236,6 @@ export class AuthenticationService {
|
||||
let headers = new HttpHeaders();
|
||||
headers = headers.set('Content-Type', 'application/x-www-form-urlencoded');
|
||||
return this.http
|
||||
.disableApiPrefix()
|
||||
.post(`${environment.oauth.serverUrl}/logout`, httpParams.toString(), { headers: headers })
|
||||
.subscribe();
|
||||
}
|
||||
@@ -318,6 +312,14 @@ export class AuthenticationService {
|
||||
}
|
||||
}
|
||||
|
||||
public saveZitadelCredentials(credentials: Credentials): void {
|
||||
this.setCredentials(credentials);
|
||||
}
|
||||
|
||||
public saveZitadeloAuthTokenDetailsStorageKey(tokenResponse: OAuth2Token): void {
|
||||
this.storage.setItem(this.oAuthTokenDetailsStorageKey, JSON.stringify(tokenResponse));
|
||||
}
|
||||
|
||||
/**
|
||||
* Following functions are for two factor authentication and require
|
||||
* first level authorization headers to be setup for the requests.
|
||||
|
||||
@@ -24,6 +24,10 @@ import { MatIcon } from '@angular/material/icon';
|
||||
import { MatLine } from '@angular/material/grid-list';
|
||||
import { STANDALONE_SHARED_IMPORTS } from 'app/standalone-shared.module';
|
||||
|
||||
/** Environment Configuration and Zitadel*/
|
||||
import { environment } from '../../../../environments/environment';
|
||||
import { AuthService } from 'app/zitadel/auth.service';
|
||||
|
||||
/**
|
||||
* Sidenav component.
|
||||
*/
|
||||
@@ -59,6 +63,17 @@ export class SidenavComponent implements OnInit, AfterViewInit {
|
||||
/** Collection of possible frequent activities */
|
||||
frequentActivities: any[] = frequentActivities;
|
||||
|
||||
/** Zitadel oidcServerEnabled */
|
||||
public environment = environment;
|
||||
oidcServerEnabled = !(
|
||||
(window as any)?.env?.oidcServerEnabled === false ||
|
||||
(window as any)?.env?.oidcServerEnabled === 'false' ||
|
||||
(window as any)?.env?.oidcServerEnabled === 0 ||
|
||||
(window as any)?.env?.oidcServerEnabled === '0' ||
|
||||
(window as any)?.env?.oidcServerEnabled === null ||
|
||||
(window as any)?.env?.oidcServerEnabled === undefined
|
||||
);
|
||||
|
||||
/* Refernce of logo */
|
||||
@ViewChild('logo') logo: ElementRef<any>;
|
||||
/* Template for popover on logo */
|
||||
@@ -82,7 +97,8 @@ export class SidenavComponent implements OnInit, AfterViewInit {
|
||||
private authenticationService: AuthenticationService,
|
||||
private settingsService: SettingsService,
|
||||
private configurationWizardService: ConfigurationWizardService,
|
||||
private popoverService: PopoverService
|
||||
private popoverService: PopoverService,
|
||||
private authService: AuthService
|
||||
) {
|
||||
this.userActivity = JSON.parse(localStorage.getItem('mifosXLocation'));
|
||||
}
|
||||
@@ -100,7 +116,11 @@ export class SidenavComponent implements OnInit, AfterViewInit {
|
||||
* Logs out the authenticated user and redirects to login page.
|
||||
*/
|
||||
logout() {
|
||||
this.authenticationService.logout().subscribe(() => this.router.navigate(['/login'], { replaceUrl: true }));
|
||||
if (this.oidcServerEnabled) {
|
||||
this.authenticationService.logout().subscribe(() => this.router.navigate(['/login'], { replaceUrl: true }));
|
||||
} else {
|
||||
this.authService.logout();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -41,6 +41,10 @@ import { NotificationsTrayComponent as NotificationsTrayComponent_1 } from '../.
|
||||
import { ThemeToggleComponent } from '../../../shared/theme-toggle/theme-toggle.component';
|
||||
import { STANDALONE_SHARED_IMPORTS } from 'app/standalone-shared.module';
|
||||
|
||||
/** Environment Configuration and Zitadel*/
|
||||
import { environment } from '../../../../environments/environment';
|
||||
import { AuthService } from 'app/zitadel/auth.service';
|
||||
|
||||
/**
|
||||
* Toolbar component.
|
||||
*/
|
||||
@@ -83,6 +87,17 @@ export class ToolbarComponent implements OnInit, AfterViewInit, AfterContentChec
|
||||
/** Sets the initial state of sidenav as collapsed. Not collapsed if false. */
|
||||
sidenavCollapsed = true;
|
||||
|
||||
/** Zitadel oidcServerEnabled */
|
||||
public environment = environment;
|
||||
oidcServerEnabled = !(
|
||||
(window as any)?.env?.oidcServerEnabled === false ||
|
||||
(window as any)?.env?.oidcServerEnabled === 'false' ||
|
||||
(window as any)?.env?.oidcServerEnabled === 0 ||
|
||||
(window as any)?.env?.oidcServerEnabled === '0' ||
|
||||
(window as any)?.env?.oidcServerEnabled === null ||
|
||||
(window as any)?.env?.oidcServerEnabled === undefined
|
||||
);
|
||||
|
||||
/** Instance of sidenav. */
|
||||
@Input() sidenav: MatSidenav;
|
||||
/** Sidenav collapse event. */
|
||||
@@ -103,7 +118,8 @@ export class ToolbarComponent implements OnInit, AfterViewInit, AfterContentChec
|
||||
private popoverService: PopoverService,
|
||||
private configurationWizardService: ConfigurationWizardService,
|
||||
private dialog: MatDialog,
|
||||
private changeDetector: ChangeDetectorRef
|
||||
private changeDetector: ChangeDetectorRef,
|
||||
private authService: AuthService
|
||||
) {}
|
||||
|
||||
/**
|
||||
@@ -140,10 +156,11 @@ export class ToolbarComponent implements OnInit, AfterViewInit, AfterContentChec
|
||||
* Logs out the authenticated user and redirects to login page.
|
||||
*/
|
||||
logout() {
|
||||
this.authenticationService.logout().subscribe(() => {
|
||||
this.notificationsTray.destroy();
|
||||
this.router.navigate(['/login'], { replaceUrl: true });
|
||||
});
|
||||
if (this.oidcServerEnabled) {
|
||||
this.authenticationService.logout().subscribe(() => this.router.navigate(['/login'], { replaceUrl: true }));
|
||||
} else {
|
||||
this.authService.logout();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user