首页 > 解决方案 > Identityserver 4 API令牌验证自省端点不起作用

问题描述

我对 identityserver4 验证模式有一些疑问。我已经用LocalValidationEndpoint测试了这些是我发现 我的 API 在 .net Framework 4.6中的区别

配置

    var IDSBearerOption = new IdentityServerBearerTokenAuthenticationOptions
                {
                    AuthenticationType = "Bearer",
                    Authority = "https://localhost:5001",
                    RequiredScopes = new[] { "api1" },
                    PreserveAccessToken = true,
                    RoleClaimType = "role",
    
                    ValidationMode = ValidationMode.Local,
                    ClientId = "TestAPI1", // Value on ApiResource
                    ClientSecret = "secret", // Value on ApiResource TestAPI1's  APIsecret
    
                };
app.UseAuthorization(opt =>
            {
                opt.AddPolicy("adminusers", policy =>
                {
                    policy.RequireAuthenticatedUser();
                    policy.RequireClaim("role", "admin"); //Also value can be checked like this

                });

            });

控制器

[Authorize]
    [RoutePrefix("api")]
    public class ValuesController : ApiController
    {
        
        [Route("values")]
        [ResourceAuthorize(Policy = "adminusers")]
        public IEnumerable<string> Get()
        {
            return new string[] { "value1", "value2" };
        }

邮差

工作正常。

提琴手

在此处输入图像描述

如果我将 ValidationMode 更改为 ValidationEndpoint 我会遇到问题 Postman

不工作。收到 403 错误 在此处输入图像描述

提琴手

在此处输入图像描述

身份服务器日志

在此处输入图像描述

查询

  1. ValidationEndpoint 和 Local 之间的区别?
  2. 何时使用 ValidationEndpoint ?
  3. 为什么 ValidationEndpoint 不起作用,为什么会出现 403 错误,如何解决这个问题?
  4. 假设验证发生在自省端点,为什么提琴手在使用“ValidationEndpoint”时没有记录流量?

标签: jwttokenidentityserver4access-token

解决方案


推荐阅读