Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

JWT auth not working #34

Closed
kalvarez2 opened this issue Jun 21, 2018 · 5 comments
Closed

JWT auth not working #34

kalvarez2 opened this issue Jun 21, 2018 · 5 comments
Assignees

Comments

@kalvarez2
Copy link

Hi
First, thanks for creating a full production application, it is a great starting point! I do have a problem:

Conditions:
I cloned the front end, made some cosmetic changes to it, still using the production server for back end, all works fine, I can log in, log out, create articles see the articles.
I cloned this one front end, asp.net core, no changes whatsoever, ran it, change the UI side environment to point to it, then I can register, log in, see the settings, log out, no problem.

Problem:
When I try to create an article, I get a 401 status code, with no more explanation on the response.

Request:
curl 'http://localhost:5000/articles/' -H 'Pragma: no-cache' -H 'Origin: http://localhost:4200' -H 'Accept-Encoding: gzip, deflate, br' -H 'Accept-Language: en-US,en;q=0.9' -H 'Authorization: Token eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJrYWx2YXJlejJAZ21haWwuY29tIiwianRpIjoiNzI0OTRkMTAtNGU0Yy00MzYwLWI1MGItNDMwMDMxYTEyMDgwIiwiaWF0IjoxNTI5NjA4OTg5LCJuYmYiOjE1Mjk2MDg5ODksImV4cCI6MTUyOTYwOTI4OSwiaXNzIjoiaXNzdWVyIiwiYXVkIjoiYXVkaWVuY2UifQ.IRmitcvS_CD9bo9kXwrO3gmQMUAS2aYTgaJpCqbESeE' -H 'Content-Type: application/json' -H 'Accept: application/json' -H 'Cache-Control: no-cache' -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.87 Safari/537.36' -H 'Connection: keep-alive' -H 'Referer: http://localhost:4200/editor' --data-binary '{"article":{"tagList":[],"title":"aaaa","description":"aaaaaaaaaaaaaaa","body":"aaaaaaaaaa"}}' --compressed

Server Log:
15:23:32 [Information] Microsoft.AspNetCore.Hosting.Internal.WebHost Request starting HTTP/1.1 OPTIONS http://localhost:5000/articles/
15:23:32 [Information] Microsoft.AspNetCore.Cors.Infrastructure.CorsService Policy execution successful.
15:23:32 [Information] Microsoft.AspNetCore.Hosting.Internal.WebHost Request finished in 0.3615ms 204
15:23:32 [Information] Microsoft.AspNetCore.Hosting.Internal.WebHost Request starting HTTP/1.1 POST http://localhost:5000/articles/ application/json 93
15:23:32 [Information] Microsoft.AspNetCore.Cors.Infrastructure.CorsService Policy execution successful.
15:23:32 [Information] Microsoft.AspNetCore.Authorization.DefaultAuthorizationService Authorization failed for user: null.
15:23:32 [Information] Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker Authorization failed for the request at filter '"Microsoft.AspNetCore.Mvc.Authorization.AuthorizeFilter"'.
15:23:32 [Information] Microsoft.AspNetCore.Mvc.ChallengeResult Executing ChallengeResult with authentication schemes (["Token", "Bearer"]).
15:23:32 [Information] Microsoft.AspNetCore.Authentication.JwtBearer.JwtBearerHandler AuthenticationScheme: "Token" was challenged.
15:23:32 [Information] Microsoft.AspNetCore.Authentication.JwtBearer.JwtBearerHandler AuthenticationScheme: "Bearer" was challenged.
15:23:32 [Information] Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker Executed action "Conduit.Features.Articles.ArticlesController.Create (Conduit)" in 0.7429ms
15:23:32 [Information] Microsoft.AspNetCore.Hosting.Internal.WebHost Request finished in 4.3307ms 401

@adamhathcock
Copy link
Collaborator

Not sure when I’ll get a chance to try it again as I’m busy for the next two weeks but I’ll try to look soon.

Which front end was giving you trouble?

@kalvarez2
Copy link
Author

Thanks for the response. Using a modified angular front end. The same front end works with the production (https://conduit.productionready.io/api)

@faouziben
Copy link

same issue here

@adamhathcock
Copy link
Collaborator

@adamhathcock
Copy link
Collaborator

This was because of the whole Token vs Bearer thing in the Authorization header again: gothinkster/realworld#81

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants