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



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

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

我已经查看了许多实现,但无法使其工作。由于 JWT 是一种标准的 impment,我不明白为什么这行不通。

这是我的 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."}

我在这里缺少什么吗?如何将声明标识添加到此状态?

最后,它被解决了。我的一个朋友调试了标识源代码,并建议增加密钥长度。增加密钥长度后,我能够验证令牌

最新更新