-
Notifications
You must be signed in to change notification settings - Fork 10.4k
OAuth 2.0 Bearer Token authentication #5717
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I want to use Json Web Tokens to create a REST API. From what I understand, ASP.Net 5 doesn't support JWT. Is it a planned feature? |
You might be interested in this SO post: http://stackoverflow.com/questions/31007470/does-asp-net-mvc6-support-oauth-2-bearer-tokens/31093557#31093557 TL;DR: the official packages developed by Microsoft for ASP.NET 5 only support OAuth2 bearer token validation. This means that...
That said, only JWT tokens are now supported OTB: the OAuth2 bearer middleware shipped with Katana 3 used to natively support opaque tokens produced by the OAuth2 authorization server, but this support has been removed.
Luckily, alternatives exist. I'm personally developing an OpenID Connect server middleware based on the OAuth2 server shipped with Katana, that offers the same low-level experience: https://github.com/aspnet-contrib/AspNet.Security.OpenIdConnect.Server For more information, you can take a look at this SO answer: http://stackoverflow.com/questions/30768015/configure-the-authorization-server-endpoint/30788109#30788109 |
+1 - #495 Would be nice to have a identity sample template using OpenIdConnectServer and JWT tokens. |
I'd be happy to collaborate with someone from the Identity team to create a template 👍 |
Any updates on this? #495 |
No update from MSFT, but you can read these two blog posts about OpenIddict, a new easy-to-use OpenID Connect server for vNext that uses ASP.NET Identity 3 and AspNet.Security.OpenIdConnect.Server: http://capesean.co.za/blog/asp-net-5-jwt-tokens/ |
here's the official statement http://leastprivilege.com/2016/01/11/announcing-identityserver-for-asp-net-5-and-net-core/ |
@leastprivilege Nice! |
Congrats @leastprivilege for the announcement! |
What I am really missing is a very simple solution to replace cookie authentication with bearer tokens. The OpenIdict examples above are going in the right direction, sadly the first is broken at the moment and the second one is, even as the folder structure itself claims, "Overengineered" (Multi-project approach, dedicated authentication server). What I am really looking for is a basic drop in the replacment for cookie authentication that adheres to the OpenId connect standard.
Special requirement from my end: Since I'm planning on doing a pure AngularJs + WebApi application, I would like the authentication (including forms, etc.) do be done with angular, so basically no MVC stuff should be required for auth. From what I've read and understand most of these things are actually supported by the projects mentioned above. Yet I haven't found any working example that provided a decent out of the box experience and kept the whole authentication mechanics and wiring to a bear minimum as described above. |
@leak if you're still experiencing issues with the OpenIddict nightly builds, feel free to open a new ticket or ping me on JabbR (https://jabbr.net/#/rooms/AspNetvNext) 👏 |
@leak I got it working using the first article (http://capesean.co.za/blog/asp-net-5-jwt-tokens/). |
Ok, after a bit of fiddling i got the example running. (No OpenIddict issue) One question remains: As far as i understand OpenIddict was created to get IdentityServer to play nice with ASP.Net 5, now that IdentityServer4 was announced it would be nice if you guys (@PinpointTownes, @leastprivilege) could ellaborate a bit what your future plans are. |
They are two different and unrelated OIDC implementations. As for your original issue -- if all you want is a Web API from your JS, then use cookies with an anti-forgery token. Microsoft is providing samples and support for that. |
True, my bad, got "OpenIdConnect.Server" mixed up. Still the question remains about the future and their particular goals. |
As mentioned by @brockallen, ASOS, OpenIddict and IdentityServer are different stacks (though OpenIddict is based on ASOS):
That said, I read IdSrv4's announcement and it's nice to see that @leastprivilege and @brockallen radically changed their minds about the way it integrates with the rest of the world (relying on Web API was a terrible idea and prevented tons of interesting scenarios in IdSrv3).
There's no plan to merge or abandon anything at this point (and AFAIK, the ASP.NET team is far too busy to directly contribute IdSrv4 or ASOS 😄) |
Hi PinpointTownes,
I get my token and add to header, with the following code:
I protect my controller with:
However I always get Unauthorized. Any recommendations? Thank you so much if you have time to respond!!! |
It was renamed/replaced by the JWT bearer middleware.
Have you tried to enable logging? |
No I haven't enabled logging. I will try and see what I get. I have a web app that I am using UseOpenIdConnectAuthentication and I protect my controllers using an ActionFilterAttribute, like this:
And it seems to work (with the exception of a few bugs that might be related to B2C being in preview) If I can figure out how to get the JWT authentication working in my Web API project, would I do something similar to check specific policies and/or roles? |
I have no idea what |
I have asked on Azure forums and support tickets, but I either get no response, or they refer me to old code samples that don't work with the latest .NET framework. It makes me wonder if they are serious with the B2C service and if it will ever get out of preview mode. Anyway, thanks so much for responding. I'll enable logging and see if I can get this figured out. |
We now have support for using IdentityServer with ASP.NET Core 3.0 which I believe covers this scenario: https://docs.microsoft.com/aspnet/core/security/authentication/identity-api-authorization |
A day late and a dollar short. |
I've been doing some digging, and I can't find anything regarding ASP.Net 5 and OAuth token based authentication. Is this a planned feature for a later release, or am I missing something?
The text was updated successfully, but these errors were encountered: