Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ui): redirect mfa on project pages #6235

Merged
merged 1 commit into from
Jul 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 15 additions & 17 deletions ui/src/app/service/authentication/error.interceptor.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { HttpErrorResponse, HttpEvent, HttpHandler, HttpInterceptor, HttpRequest } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { NavigationError, Router } from '@angular/router';
import { NavigationStart, Router } from '@angular/router';
import { TranslateService } from '@ngx-translate/core';
import { Store } from '@ngxs/store';
import { ToastService } from 'app/shared/toast/ToastService';
Expand All @@ -10,13 +10,18 @@ import { catchError, filter, first } from 'rxjs/operators';

@Injectable()
export class ErrorInterceptor implements HttpInterceptor {
lastNavigatedURL: string = '';

constructor(
private _toast: ToastService,
private _translate: TranslateService,
private _store: Store,
private _router: Router
) { }
) {
this._router.events
.pipe(filter((e): e is NavigationStart => e instanceof NavigationStart))
.subscribe(e => this.lastNavigatedURL = e.url);
}

intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
return next.handle(req).pipe(
Expand All @@ -40,25 +45,18 @@ export class ErrorInterceptor implements HttpInterceptor {
if (e.error.message) {
// 194 is the error for "MFA required. See https://github.com/ovh/cds/blob/master/sdk/error.go#L205"
if (e.error.id === 194 && confirm(`${e.error.message}.\nDo you want to login using MFA ?`)) {
this._router.events
.pipe(
filter((e): e is NavigationError => e instanceof NavigationError),
first()
)
.subscribe(e => {
this._store.dispatch(new SignoutCurrentUser()).subscribe(() => {
this._router.navigate(['/auth/ask-signin/corporate-sso'], {
queryParams: {
redirect_uri: e.url,
require_mfa: true
}
});
});
this._store.dispatch(new SignoutCurrentUser()).subscribe(() => {
this._router.navigate(['/auth/ask-signin/corporate-sso'], {
queryParams: {
redirect_uri: this.lastNavigatedURL,
require_mfa: true
}
});

});
return observableThrowError(e);
}
this._toast.errorHTTP(e.status, e.error.message, e.error.from, e.error.request_id);
this._router.navigate(['/home']);
return observableThrowError(e);
}

Expand Down
3 changes: 1 addition & 2 deletions ui/src/app/views/project/show/project.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,7 @@ export class ProjectShowComponent implements OnInit, OnDestroy, AfterViewInit {

refreshDatas(key: string): void {
let opts = [new LoadOpts('withLabels', 'labels')];
this._store.dispatch(new FetchProject({ projectKey: key, opts }))
.subscribe(null, () => this._router.navigate(['/home']));
this._store.dispatch(new FetchProject({ projectKey: key, opts }));
}

updateFav() {
Expand Down