Browse Source

Introduce OAuth failure handling

pull/2744/head
Igor Kulikov 6 years ago
parent
commit
e9553b627b
  1. 26
      ui-ngx/src/app/core/auth/auth.service.ts
  2. 3
      ui-ngx/src/assets/locale/locale.constant-en_US.json

26
ui-ngx/src/app/core/auth/auth.service.ts

@ -43,6 +43,8 @@ import { DashboardInfo } from '@shared/models/dashboard.models';
import { PageData } from '@app/shared/models/page/page-data'; import { PageData } from '@app/shared/models/page/page-data';
import { AdminService } from '@core/http/admin.service'; import { AdminService } from '@core/http/admin.service';
import { ActionNotificationShow } from '@core/notification/notification.actions'; import { ActionNotificationShow } from '@core/notification/notification.actions';
import { MatDialog, MatDialogConfig } from '@angular/material/dialog';
import { AlertDialogComponent } from '@shared/components/dialog/alert-dialog.component';
@Injectable({ @Injectable({
providedIn: 'root' providedIn: 'root'
@ -60,7 +62,8 @@ export class AuthService {
private utils: UtilsService, private utils: UtilsService,
private dashboardService: DashboardService, private dashboardService: DashboardService,
private adminService: AdminService, private adminService: AdminService,
private translate: TranslateService private translate: TranslateService,
private dialog: MatDialog
) { ) {
} }
@ -273,6 +276,7 @@ export class AuthService {
const refreshToken = this.utils.getQueryParam('refreshToken'); const refreshToken = this.utils.getQueryParam('refreshToken');
const username = this.utils.getQueryParam('username'); const username = this.utils.getQueryParam('username');
const password = this.utils.getQueryParam('password'); const password = this.utils.getQueryParam('password');
const loginError = this.utils.getQueryParam('loginError');
if (publicId) { if (publicId) {
return this.publicLogin(publicId).pipe( return this.publicLogin(publicId).pipe(
mergeMap((response) => { mergeMap((response) => {
@ -317,6 +321,10 @@ export class AuthService {
} }
) )
); );
} else if (loginError) {
this.showLoginErrorDialog(loginError);
this.utils.updateQueryParam('loginError', null);
return throwError(Error());
} }
return this.procceedJwtTokenValidate(doTokenRefresh); return this.procceedJwtTokenValidate(doTokenRefresh);
} else { } else {
@ -324,6 +332,22 @@ export class AuthService {
} }
} }
private showLoginErrorDialog(loginError: string) {
this.translate.get(['login.error', 'action.close']).subscribe(
(translations) => {
const dialogConfig: MatDialogConfig = {
disableClose: true,
data: {
title: translations['login.error'],
message: loginError,
ok: translations['action.close']
}
};
this.dialog.open(AlertDialogComponent, dialogConfig);
}
);
}
private procceedJwtTokenValidate(doTokenRefresh?: boolean): Observable<AuthPayload> { private procceedJwtTokenValidate(doTokenRefresh?: boolean): Observable<AuthPayload> {
const loadUserSubject = new ReplaySubject<AuthPayload>(); const loadUserSubject = new ReplaySubject<AuthPayload>();
this.validateJwtToken(doTokenRefresh).subscribe( this.validateJwtToken(doTokenRefresh).subscribe(

3
ui-ngx/src/assets/locale/locale.constant-en_US.json

@ -1355,7 +1355,8 @@
"password-link-sent-message": "Password reset link was successfully sent!", "password-link-sent-message": "Password reset link was successfully sent!",
"email": "Email", "email": "Email",
"login-with": "Login with {{name}}", "login-with": "Login with {{name}}",
"or": "or" "or": "or",
"error": "Login error"
}, },
"position": { "position": {
"top": "Top", "top": "Top",

Loading…
Cancel
Save