繁体   English   中英

在asp.net/Authorize中验证Node.Js JWT令牌

[英]Validating Node.Js JWT token in asp.net/Authorize

我正在将asp.net服务拆分为多个微服务。 作为一个过程,我使用Node.Js创建了我的身份服务,它使用JWT作为令牌。

现在,我想在C#中使用此令牌,以便我所有的[Authorise]属性都使用此令牌并允许访问。

我看过许多实现,但是无法使它起作用。 由于JWT是标准的实现,所以我不明白为什么它不起作用的原因。

这是我的C#代码

 public void ConfigureAuth(IAppBuilder app)
 {
            var issuer = "myorg/identity2";
            string audienceId = ConfigurationManager.AppSettings["as:AudienceId"];
            byte[] audienceSecret = TextEncodings.Base64Url.Decode
            ("xfecrrt7CV");

            // Api controllers with an [Authorize] attribute will be validated with JWT
            app.UseJwtBearerAuthentication(
                new JwtBearerAuthenticationOptions
                {
                    AuthenticationMode = AuthenticationMode.Active,
                    AllowedAudiences = new[] { audienceId },
                    IssuerSecurityTokenProviders = new IIssuerSecurityTokenProvider[]
                    {
                        new SymmetricKeyIssuerSecurityTokenProvider(issuer, audienceSecret)
                    }
                });

但是,每次尝试访问受保护的方法时,都会出现此错误。

{"Message":"Authorization has been denied for this request."}

我在这里想念什么吗? 我该如何添加索赔身份?

终于解决了。 我的一位朋友调试了Identity源代码,并建议增加密钥长度。 增加密钥长度后,我可以验证令牌

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM