ASP.NET 5 JWT承载令牌流 [英] ASP.NET 5 JWT Bearer Token Flow

查看:576
本文介绍了ASP.NET 5 JWT承载令牌流的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道有很多关于这个,但没有其他问题回答了我的查询尚未使用ASP.NET 5 BETA4或更高。

I know there are a lot of other questions about this but nothing has answered my query as yet with beta4 or higher of ASP.NET 5.

我要的是一个方法

JWT生成和智威汤逊消费ASP.NET 5。

JWT Generation and JWT Consumption in ASP.NET 5.

没有OAuth2流程,我确实有IdentityServerv3用的OAuth2工作,但它仅仅是矫枉过正一个单一的应用程序访问的API,当我自己的两面。

No OAuth2 flow, I do have the IdentityServerv3 working with OAuth2 but it is just overkill for a single app accessing an API when I own both sides.

我有在此列表中是查不到Microsoft.Owin.Security.Jwt相当于在ASP.NET 5.没有任何的https://www.myget.org/gallery/aspnetvnext 似乎涉及。或者是,实际上包留在有关与vNext?

The main source of difficulty I am having is finding out the equivalent of Microsoft.Owin.Security.Jwt in ASP.NET 5. Nothing in this list https://www.myget.org/gallery/aspnetvnext seems to relate. Or is that package actually to stay relevant in with vNext?

推荐答案

如果你正在寻找一个(简单)的方式来生成自己的JWT令牌,你应该直接使用 JwtSecurityTokenHandler 。您可以在 System.IdentityModel.Tokens 包放在你所提到的MyGet库找到它(但版本有点现在老了),或者直接在Azure的AD库,在在 System.IdentityModel.Tokens.Jwt 包:的https: //www.myget.org/gallery/azureadwebstacknightly

If you're looking for a (simple) way to generate your own JWT tokens, you should directly use the JwtSecurityTokenHandler. You can find it in the System.IdentityModel.Tokens package on the MyGet repository you mentioned (but the version is a bit old now) or directly on the Azure AD repository, in the System.IdentityModel.Tokens.Jwt package: https://www.myget.org/gallery/azureadwebstacknightly

当然,使用标准的协议来发布和检索您的JWT令牌超过和推荐的OAuth2和OpenID连接可能为最佳人选。

Of course, using a standard protocol to issue and retrieve your JWT tokens is more than recommended and OAuth2 and OpenID Connect are probably the best candidates for that.

注意 IdentityServer 的不是对ASP.NET 5.我亲自随武士刀3的OAuth2授权服务器中间件的先进叉工程工作的唯一服务器和提供不同的方法: https://github.com/aspnet-contrib/AspNet.Security。 OpenIdConnect.Server

Note that IdentityServer is not the only server that works on ASP.NET 5. I'm personally working on an advanced fork of the OAuth2 authorization server middleware that comes with Katana 3 and that offers a different approach: https://github.com/aspnet-contrib/AspNet.Security.OpenIdConnect.Server

app.UseOAuthBearerAuthentication(new JwtBearerOptions {
    AutomaticAuthenticate = true,
    AutomaticChallenge = true,
    Audience = "http://localhost:54540/",
    Authority = "http://localhost:54540/"
});

app.UseOpenIdConnectServer(options => {
    options.Provider = new AuthorizationProvider();
});

随意ping通我的 https://jabbr.net/#/rooms/AspNetCore如果你需要更多的信息。

Feel free to ping me on https://jabbr.net/#/rooms/AspNetCore if you need more information.

这篇关于ASP.NET 5 JWT承载令牌流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆