【问题标题】:No SecurityTokenValidator available for token没有可用于令牌的 SecurityTokenValidator
【发布时间】:2016-02-11 11:32:08
【问题描述】:

我创建了一个IdentityServer,并且可以通过将ClientIdClientSecret 传递给令牌端点来成功检索令牌

我的 IndetityServer 设置如下

var certFile = env.ApplicationBasePath + $"{Path.DirectorySeparatorChar}idsrv3test.pfx";

var options = new IdentityServerOptions
{
    Factory = new IdentityServerServiceFactory()
        .UseInMemoryClients(Client.Get())
        .UseInMemoryScopes(Scope.Get())
        .UseInMemoryUsers(User.Get()),
            SigningCertificate = new X509Certificate2(certFile, "idsrv3test"),
            RequireSsl = false
};

app.UseIdentityServer(options);

当我调用受保护的 MVC 6 Web API 时,我得到一个

没有可用于令牌的 SecurityTokenValidator: c7f2c3890d83a454fcb504cb96c75fe7

这是我的 API 的 Startup.cs 中的设置

app.UseJwtBearerAuthentication(options =>
{
    options.Authority = $@"{tokenServiceUrl}";
    options.Audience = $@"{tokenServiceUrl}/resources";
    options.AutomaticAuthenticate = true;
    options.RequireHttpsMetadata = false;
});

我确保此设置在app.UseMvc() 调用之前完成。我还有什么需要做的吗?

【问题讨论】:

    标签: c# asp.net-core asp.net-core-mvc identityserver3


    【解决方案1】:

    运行

    安装包 IdentityServer3.AccessTokenValidation.Integration.AspNet -Pre

    从包管理器控制台为您的 API 安装集成包。然后将以下代码添加到 API 的 Startup.cs 类的 Configure 方法中

    app.UseIdentityServerBearerTokenAuthentication
    (
        new IdentityServerBearerTokenAuthenticationOptions
        {
            Authority = tokenServiceUrl,
            ValidationMode = ValidationMode.ValidationEndpoint,
            RequiredScopes = new[] { "SomeScope" }
        }
    );
    

    【讨论】:

      猜你喜欢
      • 2016-09-17
      • 2020-03-27
      • 2019-10-18
      • 1970-01-01
      • 2018-03-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多