Asp.net core Identityserver4中的函数内省客户端始终返回Unauthorized
我想使用函数IntrospectionClient来验证identity server中的令牌,但它总是返回: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
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");