Giter VIP home page Giter VIP logo

Comments (9)

slintes avatar slintes commented on May 19, 2024

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.

einsitang avatar einsitang commented on May 19, 2024

@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.

einsitang avatar einsitang commented on May 19, 2024

@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.

slintes avatar slintes commented on May 19, 2024

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.

einsitang avatar einsitang commented on May 19, 2024

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.

escardin avatar escardin commented on May 19, 2024

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.

einsitang avatar einsitang commented on May 19, 2024

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.

chenkie avatar chenkie commented on May 19, 2024

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.

einsitang avatar einsitang commented on May 19, 2024

thanks all guys @chenkie @slintes @escardin 👍

from angular2-jwt.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.