angular2-jwt icon indicating copy to clipboard operation
angular2-jwt copied to clipboard

JwtModule not attaching authorization token in request

Open ilmcraft opened this issue 7 years ago • 8 comments

I have configured JwtModule in my Angular app. According to documentation 'Any requests sent using Angular's HttpClient will automatically have a token attached as an Authorization header.' But it's not working ... Can you please check and test the repositories code again?

ilmcraft avatar Sep 09 '19 08:09 ilmcraft

I'm having the same problem. @mdhelaluddin-ctg-bd have you gotten anywhere with it?

circuitBurn avatar Sep 14 '19 12:09 circuitBurn

@mdhelaluddin-ctg-bd @circuitBurn Could you share a repro where we can take a look?

stevehobbsdev avatar Sep 16 '19 09:09 stevehobbsdev

@stevehobbsdev I have this same issue. Here is my repo: https://github.com/BartoszBartniczak/todo-angular/tree/jwt

If you need API app, here it is: https://github.com/BartoszBartniczak/symfony-todo-app/tree/jwt

BartoszBartniczak avatar Sep 19 '19 17:09 BartoszBartniczak

I have the same issue. Any solution ?

stingers avatar Sep 23 '19 07:09 stingers

m having the

Nope. Didn't find any solution.

ilmcraft avatar Sep 23 '19 08:09 ilmcraft

@mdhelaluddin-ctg-bd I've noticed in your code that you're using a full origin value in the whitelist array: https://github.com/BartoszBartniczak/todo-angular/blob/jwt/src/app/app.module.ts#L58

Can you try just setting it as todo-api.test (without the scheme) and see if that works for you?

stevehobbsdev avatar Sep 23 '19 11:09 stevehobbsdev

@stevehobbsdev Your tip was realy helpfull, although it didn't fix the bug at the begining: image

I needed to change the nginx config and add Authorization as accepted header: 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,Authorization';

But after that change I couldn't log in: image

I changed the blacklistedRoutes:

blacklistedRoutes: [
          'todo-api.test/login_check',
        ],

which seems to be correct, with documentation, but still doesn't work.

When I turned off the throwNoTokenError option, everything started to work, which is a little bit weird.

It looks like, it tries to get token before checking blacklisted routes.

Thank you for your help. Everything working fine right now.

BartoszBartniczak avatar Sep 23 '19 12:09 BartoszBartniczak

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you have not received a response for our team (apologies for the delay) and this is still a blocker, please reply with additional information or just a ping. Thank you for your contribution! 🙇‍♂️

stale[bot] avatar Dec 22 '19 13:12 stale[bot]