jwtBearer承载令牌RC-1更新ASP.Net 5 [英] jwtBearer bearer token with rc-1 update to ASP.Net 5

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

问题描述

我有一个很大的麻烦我的asp.net 5 web应用程序能够接受智威汤逊标记。我有code已经全功能使用mvc5,只是想一些帮助这个转换code是相同的,但与mvc6工作。它被设置的方式是我的客户(网站)是一个值得信赖的应用程序,并使用 IssuerSigningToken 来验证信任的应用程序的状态,在那之后我可以只通智威汤逊标记,并得到用户和认证服务器宣称的细节了。

I am having a lot of trouble getting my asp.net 5 web app to be able to accept JWT tokens. I have the code already fully functional using mvc5 and just want some help converting this code to be identical but work with mvc6. The way it is set up is my client (web-site) is a trusted app and uses an IssuerSigningToken to validate the trusted app status, and after that I can just pass JWT tokens and get user and claims details back from auth server.

老code:

public void Configuration(IAppBuilder app)
{
    HttpConfiguration httpConfig = new HttpConfiguration();
    app.UseJwtBearerAuthentication(new MyJwtOptions());
    app.UseWebApi(httpConfig);
    ConfigureWebApi(httpConfig);
    app.UseWebApi(httpConfig);
}

public class MyJwtOptions : JwtBearerAuthenticationOptions
{
    public MyJwtOptions()
    {
        var issuer = "https://tv.domain.com/trust/domain";
        var audience = "https://www.domain.com/";
        var key = Convert.FromBase64String("dW8E7DDKW34DDW33jg=");
        AllowedAudiences = new[] {audience};
        IssuerSecurityTokenProviders = new[] {new SymmetricKeyIssuerSecurityTokenProvider(issuer, key)};
    }
}

我能找到一种接近最好的例子就是在这里 - JwtBearerSample

        app.UseJwtBearerAuthentication(options =>
        {
            options.AutomaticAuthenticate = true;
            options.AutomaticChallenge = true;
            // You also need to update /wwwroot/app/scripts/app.js
            options.Authority = Configuration["jwt:authority"];
            options.Audience = Configuration["jwt:audience"];
        });

我想不通,如果我靠近与否,我的主要问题是如何将我添加 IssuerSignerToken ?我使用 Thinktecture ,它似乎并不像他们有任何新的最高最新的例子了没有。有没有人完成了什么,我想干什么?我知道还有其他一些类似的问题,而是给那些使用 X.509证书的的答复,我会preFER尽可能使用相同的字符串键 IssuerSignerToken

I can not figure out if I am close or not, my main problem is how to I add the IssuerSignerToken ? I am using Thinktecture , and it doesn't seem like they have any new up-to-date example up yet. Has anyone accomplished what I am trying to do? I know there are several other similar questions , but the responses to those use X.509 Certificates , I would prefer if possible to use the same string key for IssuerSignerToken

我的问题是我用从 Microsoft.Owin.Security.JwtBearerAuthenticationOptions 继承了新的code期望的选项
  Microsoft.AspNet.Authentication.JwtBearer.JwtBearerOptions

my problem is the options I used to use inherited from Microsoft.Owin.Security.JwtBearerAuthenticationOptions the new code expects Microsoft.AspNet.Authentication.JwtBearer.JwtBearerOptions

推荐答案

要使用对称密钥,您将需要迁移到RC2每晚构建(它不会与本地RC1工作)。

To use a symmetric key, you'll need to migrate to the RC2 nightly builds (it won't work natively with RC1).

下面是你如何能指定验证JWT令牌需要发行方密钥(你不必继承 JwtBearerOptions JwtBearerAuthenticationOptions 为):

Here's how you can specify the issuer key needed to validate JWT tokens (you don't need to subclass JwtBearerOptions or JwtBearerAuthenticationOptions for that):

var key = Convert.FromBase64String("dW8E7DDKW34DDW33jg=");

app.UseJwtBearerAuthentication(options => {
    options.AutomaticAuthenticate = true;
    options.AutomaticChallenge = true;

    options.Authority = Configuration["jwt:authority"];
    options.Audience = Configuration["jwt:audience"];

    options.TokenValidationParameters.IssuerSigningKey = new SymmetricSecurityKey(key);
});

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

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