-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e66d483
commit 1f10afd
Showing
16 changed files
with
247 additions
and
20 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* tslint:disable */ | ||
/* eslint-disable */ | ||
import { HttpClient, HttpContext, HttpResponse } from '@angular/common/http'; | ||
import { Observable } from 'rxjs'; | ||
import { filter, map } from 'rxjs/operators'; | ||
import { StrictHttpResponse } from '../../strict-http-response'; | ||
import { RequestBuilder } from '../../request-builder'; | ||
|
||
import { AuthenticationResponse } from '../../models/authentication-response'; | ||
import { RefreshTokenRequest } from '../../models/refresh-token-request'; | ||
|
||
export interface RefreshToken$Params { | ||
body: RefreshTokenRequest | ||
} | ||
|
||
export function refreshToken(http: HttpClient, rootUrl: string, params: RefreshToken$Params, context?: HttpContext): Observable<StrictHttpResponse<AuthenticationResponse>> { | ||
const rb = new RequestBuilder(rootUrl, refreshToken.PATH, 'post'); | ||
if (params) { | ||
rb.body(params.body, 'application/json'); | ||
} | ||
|
||
return http.request( | ||
rb.build({ responseType: 'json', accept: 'application/json', context }) | ||
).pipe( | ||
filter((r: any): r is HttpResponse<any> => r instanceof HttpResponse), | ||
map((r: HttpResponse<any>) => { | ||
return r as StrictHttpResponse<AuthenticationResponse>; | ||
}) | ||
); | ||
} | ||
|
||
refreshToken.PATH = '/auth/refresh-token'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
/* tslint:disable */ | ||
/* eslint-disable */ | ||
export interface AuthenticationResponse { | ||
token?: string; | ||
access_token?: string; | ||
refresh_token?: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/* tslint:disable */ | ||
/* eslint-disable */ | ||
export interface RefreshTokenRequest { | ||
accessToken?: string; | ||
refreshToken?: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { | ||
HttpRequest, | ||
HttpHandler, | ||
HttpEvent, | ||
HttpInterceptor, | ||
HttpErrorResponse, | ||
HttpClient | ||
} from '@angular/common/http'; | ||
import { HTTP_INTERCEPTORS } from '@angular/common/http'; | ||
import { catchError, Observable, switchMap } from 'rxjs'; | ||
import { JwtTokenService } from '../services/jwt-token.service'; | ||
import { RefreshTokenService } from '../services/refresh-token.service'; | ||
import { refreshToken } from 'app/api/fn/authentication/refresh-token'; | ||
import { from } from 'rxjs'; | ||
import { environment } from 'app/core/environments/environment'; | ||
|
||
|
||
@Injectable() | ||
export class RefreshInterceptor implements HttpInterceptor { | ||
|
||
constructor(private refreshTokenService: RefreshTokenService, private jwtTokenService: JwtTokenService, private http: HttpClient) {} | ||
|
||
intercept(request: HttpRequest<unknown>, next: HttpHandler): Observable<HttpEvent<unknown>> { | ||
return next.handle(request).pipe( | ||
catchError((error: HttpErrorResponse) => { | ||
if (error.status === 401 || error.status === 403) { | ||
const params = { | ||
body: { | ||
access_token: this.jwtTokenService.token, | ||
refresh_token: this.refreshTokenService.token | ||
} | ||
} | ||
|
||
return this.http.post(`${environment.apiBaseUrl}/auth/refresh-token`, params).pipe( | ||
switchMap((response: any) => { | ||
this.jwtTokenService.token = response.access_token!; | ||
this.refreshTokenService.token = response.refresh_token!; | ||
request = request.clone({ | ||
setHeaders: { | ||
Authorization: `Bearer ${response.access_token}` | ||
} | ||
}); | ||
return next.handle(request); | ||
}), | ||
catchError((error: HttpErrorResponse) => { | ||
this.refreshTokenService.removeToken(); | ||
return from(Promise.reject(error)); | ||
}) | ||
); | ||
}else { | ||
return from(Promise.reject(error)); | ||
} | ||
} | ||
|
||
|
||
)); | ||
} | ||
|
||
} | ||
|
||
|
||
|
||
export const refreshInterceptorProvider = { | ||
provide: HTTP_INTERCEPTORS, | ||
useClass: RefreshInterceptor, | ||
multi: true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { Injectable } from '@angular/core'; | ||
|
||
|
||
@Injectable({ | ||
providedIn: 'root' | ||
}) | ||
export class RefreshTokenService { | ||
|
||
constructor() { } | ||
|
||
set token(token: string) { | ||
localStorage.setItem('refresh_token', token); | ||
} | ||
|
||
get token() { | ||
return localStorage.getItem('refresh_token') as string; | ||
} | ||
|
||
removeToken(): void { | ||
localStorage.removeItem('refresh_token'); | ||
} | ||
|
||
isTokenExist(): boolean { | ||
return !!this.token; | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletion
1
frontend/src/app/modules/auth/pages/activate-account/activate-account.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.