This commit is contained in:
2023-10-12 21:18:03 +07:00
parent e7678c0e5e
commit 36efa12651
24 changed files with 378 additions and 256 deletions

View File

@@ -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)
// })
// );
}
}

View 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}`)
}
}