Comments (9)
that's not specific to angular2-jwt, it's a plain angular2 http topic. Check first example here: https://angular.io/docs/js/latest/api/http/Http-class.html
from angular2-jwt.
@slintes I just change thing Type to any
.
my server is java
with jjwt
, how ro response this request ? have any sample code pls.
from angular2-jwt.
@slintes I saw the angular2-jwt
code , the _request
just merge HttpOptions, with response
,do nothing with jwt?
what is angular2-jwt
do ? I dont understand
from angular2-jwt.
angular2-jwt checks if you have a valid jwt token, and if so it adds it to the header of the http request. It's just a wrapper around angular2's http module, with some extras.
On server side you have to also check if the token is valid, and if the user is allowed to access the requested resource. I don't know jjwt
, so I don't have example code.
Probably you want your server to return some json data. If so, you can use Response.json() in the subscribe() method, in order to map json to whatever type. See link in my response above to see how to do that...
from angular2-jwt.
when I frist enter my app , have not jwt token in headers.
so , when I use authHttp
do something, will throws exception , so I need set noJwtError : true
,
but I after first request then server response a string (this is a jwt token?I use jwtHelper.decodeToken
can found real value ),and I need the put this string on localStorge['id_token']?
and next time I use authHttp
to request(post、get、delete or something else method) server , I need read the 'Authorization' in request headers? and verify the token ?
it that the process working with jwt ?
sorry ! my english no good , can U understand what I mean ?
from angular2-jwt.
AuthHttp is for sending requests with your JWT token, it does not handle fetching the token and saving it in local storage. You should use regular Http requests to get your token, and then save the token in local storage where AuthHttp will find it.
To your initial comment, about the type of the object you get back: It will always be a response object, which has fields for getting headers, status codes, etc... If you want to get the actual payload you need to do response.text() or response.json(). Typings don't exist at runtime and it won't coerce stuff into say, strings or objects for you. You should always set your types based on what they actually are/will be at run time and not what you think they are.
from angular2-jwt.
that mean I need use Http
to get a authorization,and this authorization is that jwt?
and I need save it in local storage with name 'id_token'(or just other name).
then I can use authHttp
to do request thing,and they will use JWT token all the time?
so , in addition to login action,after authorization action alway need verify the token by request headers?
from angular2-jwt.
Thanks @slintes and @escardin :)
@forfuns that's correct, you need to have your server set up to issue a JWT when the user logs in and then store it in local storage. That is done using the regular Http
class. Then you can use AuthHttp
and the JWT will be sent as an Authorization
header automatically to access protected resources. :)
from angular2-jwt.
thanks all guys @chenkie @slintes @escardin 👍
from angular2-jwt.
Related Issues (20)
- Error: The inspected token doesn't appear to be a JWT. Check to make sure it has three parts and see https://jwt.io for more. HOT 1
- Angular 12 support HttpInterceptor Context HOT 4
- Angular 13 support HOT 28
- upstream dependency conflict while installing angular2-jwt package using angular-cli HOT 1
- ``
- v5.1.0 broke azure devops publishing HOT 5
- Please respect semver HOT 3
- tokenGetter does not support Promise HOT 2
- Getting an issue of no exported member from angular core HOT 1
- Encourage the library authors to publish an Ivy distribution HOT 2
- Release v5.1.1 decodeToken<T = any>(token?: string): T | Promise<T> HOT 4
- 'ɵɵngDeclareFactory' (imported as 'i0') was not found in '@angular/core' HOT 2
- Authorization header stops going through after the browser sits idle for a while. HOT 7
- JwtInterceptor not work HOT 2
- No header with standalone components HOT 4
- Angular 16 support HOT 1
- Package not working with es2022 HOT 4
- Angular JWT 5.0.2 not compiling with Angular 13.3.6 HOT 1
- App no longer working after installing auth0 HOT 1
- angular2-jwt is way outdated.
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 angular2-jwt.