Closed Tratcher closed 8 years ago
@ryanelian @Tratcher The library was designed to be secure by default. That means a few things: https for metadata retrieval, tokens signed, key sizes of sufficient length, issuer validation, audience validation, expiration times checked, nonce checks, c_hash and at_hash checks, etc. We want to make sure that if someone turns off say, AudienceValidation {which opens up a forwarding attack}, they do so with their eyes open.
That said integration with asp.net core 1.0 could be better. We could relax some items if say env.IsDevelopmentEnvironment() was true.
It looks like we could help users by improving our docs. Thanks for taking the time to detail your experience. Stackoverflow would benefit from such a question.
That said integration with asp.net core 1.0 could be better. We could relax some items if say env.IsDevelopmentEnvironment() was true.
Maybe instead of that, if in development make it so it can log or emit message containing the reason that the authorization failed? That'd help tremendously.
It looks like we could help users by improving our docs.
Please do! That'd be a godsend.
When I Google UseJwtBearerAuthentication
, the only relevant results that appear is this:
https://stormpath.com/blog/token-authentication-asp-net-core
I would greatly appreciate it if there are documentations in http://docs.asp.net/ regarding the security middlewares.
That said integration with asp.net core 1.0 could be better. We could relax some items if say env.IsDevelopmentEnvironment() was true.
That seems like a really bad idea to me.
Maybe if in development, make it so it can log or emit message containing the reason that the authorization failed? That'd help tremendously.
Doesn't it do that via logging already?
Doesn't it do that via logging already?
I'm not aware of that. I will check later. Thank you for telling me.
@leastprivilege I am thinking only about relaxing https for now not requirements such as 'aud' etc. I should have been more specific. I am finding that in 'dev' mode sometimes https gets in the way.
I think we have what we need from this thread.
Thanks so much.
Thanks
From @ryanelian on August 28, 2016 14:56
I am trying to develop a ASP.NET application using JWT for securing certain routes and then decided that I would use
app.UseJwtBearerAuthentication()
to make my life easier by not reinventing the wheel. (And so I can use[Authorize]
and call it a day)However, instead of speeding up an entire day of work, I ended up investigating for hours why a perfectly fine
Authorization: Bearer insert_jwt_token_here
results in 401 Unauthorized response from the server.The token in question was generated using the trusty jose-jwt and successfully parsed and verified using jwt.io and the jose-jwt itself so I'm quite confident that the token is correct.
After hours of browsing and reading blogs with no avail, I decided to download the source from Release branch directly and perform step by step debugging by putting a breakpoint in
JwtBearerHandler
. (Curiously,Microsoft.AspNetCore.Authentication
failed to compile unless I enable the nightly myget feed for alpha 1.1.0, becauseMicrosoft.Extensions.SecurityHelper.Sources
1.0.0 doesn't exist in NuGet.)Surprisingly, the token in question was failed to be validated by the signature validator because of this:
Apparently, my development secret key
ACCELISTROCKS!
was too short according to the validator. This is quite an undocumented surprise. So I ended up increasing the secret key toACCELISTROCKSBOOMBOOMFIRE!
and the validator works.However, the token failed to be validated once again:
I didn't remember asking the TokenValidationParameters to validate Audience...
So I ended up putting these into the
TokenValidationParameters
for good measure:After I did that, the authorization finally works as intended.
I hope this issue can serve as a mini-blog for other people who are scratching their head over this issue.
Copied from original issue: aspnet/Security#959