Comments (3)
it should automatically refresh token if the previous request fails with access token failure.
First of all, you have to identify refresh token request, so the library won't intercept it and won't add extra refresh token functionality for particular request:
public verifyTokenRequest(url: string): boolean {
return url.endsWith('refresh-token');
}
then you have to tell library that previous request failed because of the access token failure:
public refreshShouldHappen(response: HttpErrorResponse): boolean {
return response.status === 401; // for example at this point we need to refresh token
}
from ngx-auth.
Yes. I have these functions in place. And I do see that the refresh api is getting called whenever the original request returns 401.
But my api does not return any refresh_token. It refreshes any expired token based on access_token only which I need to pass along with my '/refresh' call. But the refresh request does not seem to have the 'Authorization: Bearer' in the header. So my api is returning invalid token response. I have found a quick workaround. I can pass the token as query param with the url. But is there any better way!
public refreshToken(): Observable<any> {
return this.tokenStorage
.getAccessToken()
.pipe(
switchMap((accessToken: string) =>
this.http.post(`http://localhost/uku/api/auth/refresh?token=${accessToken}`, {})
),
tap((tokens: any) => {
this.saveAccessData(tokens.data.accessToken);
}),
catchError((err) => {
this.logout();
return Observable.throw(err);
})
);
}
from ngx-auth.
if refresh token is verified properly via verifyTokenRequest
interceptor won't add any tokens to the request, it won't process that request at all see https://github.com/serhiisol/ngx-auth-example/blob/master/src/app/shared/authentication/authentication.service.ts#L51
from ngx-auth.
Related Issues (20)
- Private guard remember URL HOT 1
- Unable to integrate with Spring Boot: getting "_a is null" and no tokens. HOT 3
- Add canLoad support HOT 1
- ERROR TypeError: Cannot read property 'pipe' of undefined HOT 1
- Use without refresh token HOT 1
- same useValue HOT 2
- Angular 7 build HOT 3
- Feature: add ability to check request if it has to have auth token
- Decode Claim Information HOT 2
- Whitelist/Blacklist URL HOT 5
- Angular 8 compatibility HOT 4
- Feature: Implementation of unit tests for services and guards HOT 1
- Angular material compatibility HOT 6
- Security conciderations HOT 5
- verifyRefreshToken receiving wrong parameter HOT 4
- ERROR in node_modules/ngx-auth/auth.module.d.ts HOT 2
- Refresh the token before making a new request HOT 2
- ngcc Processing legacy "View Engine" HOT 1
- Angular 16 compatibility HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ngx-auth.