Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-core/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net core Identityserver4中的函数内省客户端始终返回Unauthorized_Asp.net Core_Identityserver4 - Fatal编程技术网

Asp.net core Identityserver4中的函数内省客户端始终返回Unauthorized

Asp.net core Identityserver4中的函数内省客户端始终返回Unauthorized,asp.net-core,identityserver4,Asp.net Core,Identityserver4,我想使用函数IntrospectionClient来验证identity server中的令牌,但它总是返回:Unauthorized 标识服务器启动代码: services.AddIdentityServer() .AddSigningCredential(myPrivatecert) .AddInMemoryApiResources(Config.GetResources()) .AddInMemoryClients(C

我想使用函数IntrospectionClient来验证identity server中的令牌,但它总是返回:Unauthorized

标识服务器启动代码:

services.AddIdentityServer()
            .AddSigningCredential(myPrivatecert)
            .AddInMemoryApiResources(Config.GetResources())
            .AddInMemoryClients(Config.GetClients())
            .AddTestUsers(Config.GetTestUsers())
            .AddValidationKey(myPubliccert)
            .AddJwtBearerClientAuthentication()
            .AddValidators();
我在配置文件中添加了一个api资源、一个客户端信息和一个测试用户

我的配置是:

public class Config
{
    //ApiResource
    public static IEnumerable<ApiResource> GetResources()
    {
        return new List<ApiResource>
        {
            new ApiResource("api")
        };
    }

    //Client
    public static IEnumerable<Client> GetClients()
    {
        return new List<Client>
        {
            new Client()
            {
                ClientId = "site",
                AccessTokenLifetime = 180,
                RefreshTokenExpiration = TokenExpiration.Absolute,
                AbsoluteRefreshTokenLifetime = 1800,
                AllowedGrantTypes = GrantTypes.ResourceOwnerPassword,
                ClientSecrets =
                {
                    new Secret("secret".Sha256())
                },
                AlwaysSendClientClaims = true,
                AllowAccessTokensViaBrowser = true,
                RequireConsent = false,
                AllowedScopes =
                {
                    "api"
                },
                AccessTokenType = AccessTokenType.Jwt,
                AllowOfflineAccess = true
            },
        };
    }

    //TestUser
    public static List<TestUser> GetTestUsers()
    {
        return new List<TestUser>{
            new TestUser{
                SubjectId="1",
                Username="wyt",
                Password="123456",
                Claims = new List<Claim>()
                {
                    new Claim("wawa", "aoao"),
                }
            }
        };
    }
}
获取令牌:

        //token
        var tokenClient = new TokenClient(dico.TokenEndpoint, "site", "secret");
        var tokenResponse = tokenClient.RequestResourceOwnerPasswordAsync("wyt", "123456").Result;
想要使用内省:

var introspectionClient = new IntrospectionClient(
            dico.IntrospectionEndpoint,
            "api",
            "secret");

        var vresponse = await introspectionClient.SendAsync
            (
                new IntrospectionRequest { Token = tokenResult.AccessToken }
            );
但是vresponse总是未经授权的
哪里错了?

我遇到了同样的问题,文档不是很清楚。 您需要将ApiSecret添加到您的ApiResource:

public static IEnumerable<ApiResource> GetResources()
{
    return new List<ApiResource>
    {
        new ApiResource("api") 
        {
            ApiSecrets = { new Secret("secret".Sha256()) }
        }
    };
}

我也有同样的问题,你能解决吗?
public static IEnumerable<ApiResource> GetResources()
{
    return new List<ApiResource>
    {
        new ApiResource("api") 
        {
            ApiSecrets = { new Secret("secret".Sha256()) }
        }
    };
}
var introspectionClient = new IntrospectionClient(
        dico.IntrospectionEndpoint,
        "api",
        "secret");