[update]
This commit is contained in:
@@ -1,44 +1,37 @@
|
||||
import { OidcAuthService } from 'src/app/core/oidc/oidc.service';
|
||||
import { Injectable } from '@angular/core';
|
||||
import {
|
||||
HttpRequest,
|
||||
HttpHandler,
|
||||
HttpEvent,
|
||||
HttpInterceptor
|
||||
HttpRequest,
|
||||
HttpHandler,
|
||||
HttpEvent,
|
||||
HttpInterceptor
|
||||
} from '@angular/common/http';
|
||||
import { Observable, throwError } from 'rxjs';
|
||||
import { catchError, finalize } from 'rxjs/operators';
|
||||
import { Router } from '@angular/router';
|
||||
import { NgProgress } from 'ngx-progressbar';
|
||||
import { ApplicationSecurityService } from '../service/security/application-security.service';
|
||||
|
||||
@Injectable()
|
||||
export class TokenIntercepterInterceptor implements HttpInterceptor {
|
||||
|
||||
constructor(
|
||||
private odicSV: OidcAuthService,
|
||||
private router: Router,
|
||||
private progress: NgProgress,
|
||||
private appTokenSV: ApplicationSecurityService
|
||||
) {
|
||||
}
|
||||
constructor(
|
||||
private router: Router,
|
||||
) {
|
||||
}
|
||||
|
||||
intercept(request: HttpRequest<unknown>, next: HttpHandler): Observable<HttpEvent<unknown>> {
|
||||
const isRegisterSubjectAPI = request.url.includes('rsu-reg-api')
|
||||
const customReq = request.clone({
|
||||
setHeaders:{
|
||||
Authorization: request.url.includes('app_tokens') ? `${this.odicSV.getAuthorizationHeaderValue()}` : `Bearer ${this.appTokenSV.getToken()}`
|
||||
}
|
||||
});
|
||||
this.progress.ref('progressBar').start()
|
||||
return next.handle(customReq).pipe(
|
||||
finalize(() => this.progress.ref('progressBar').complete()),
|
||||
catchError(err => {
|
||||
if (err.status == 401) {
|
||||
this.router.navigate(['./'],{ replaceUrl: true })
|
||||
}
|
||||
return throwError(err)
|
||||
})
|
||||
);
|
||||
}
|
||||
intercept(request: HttpRequest<unknown>, next: HttpHandler): Observable<HttpEvent<unknown>> {
|
||||
const customReq = request.clone({
|
||||
setHeaders: {
|
||||
// Authorization: request.url.includes('app_tokens') ? `${this.odicSV.getAuthorizationHeaderValue()}` : `Bearer ${this.appTokenSV.getToken()}`
|
||||
}
|
||||
});
|
||||
return next.handle(customReq)
|
||||
// return next.handle(customReq).pipe(
|
||||
// finalize(() => this.progress.ref('progressBar').complete()),
|
||||
// catchError(err => {
|
||||
// if (err.status == 401) {
|
||||
// this.router.navigate(['./'], { replaceUrl: true })
|
||||
// }
|
||||
// return throwError(err)
|
||||
// })
|
||||
// );
|
||||
}
|
||||
}
|
||||
|
||||
20
src/app/core/service/auth/auth.service.ts
Normal file
20
src/app/core/service/auth/auth.service.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { BaseService } from 'src/app/core/base/base-service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class AuthService extends BaseService{
|
||||
|
||||
constructor(
|
||||
public http: HttpClient
|
||||
) {
|
||||
super('/common/user_login', http)
|
||||
}
|
||||
|
||||
login(payload : {'loginname': string , 'password' : string}){
|
||||
return this.http.get(`${this.prefix}/common/user_login/login/${payload.loginname}/${payload.password}`)
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user