C# IdentityServer 4用户信息终结点返回禁止状态
我刚开始使用identityserver4,无法理解用户信息端点返回禁止状态的原因C# IdentityServer 4用户信息终结点返回禁止状态,c#,identityserver4,C#,Identityserver4,我刚开始使用identityserver4,无法理解用户信息端点返回禁止状态的原因 public static IEnumerable<Client> GetClients() { return new List<Client> { new Client { ClientId = "client1", Allowe
public static IEnumerable<Client> GetClients()
{
return new List<Client>
{
new Client
{
ClientId = "client1",
AllowedGrantTypes = GrantTypes.ResourceOwnerPassword,
ClientSecrets =
{
new Secret("secret".Sha256())
},
AllowedScopes =
{
"api1",
IdentityServerConstants.StandardScopes.OpenId,
IdentityServerConstants.StandardScopes.Profile,
},
IncludeJwtId = true,
RequireConsent = false,
AlwaysIncludeUserClaimsInIdToken = true,
AlwaysSendClientClaims = true,
}
};
}.
为什么我在userinfo端点中获得禁止的状态码?
感谢您的帮助 首先检查您的客户端配置。在GetClients中有一个ClientId=client1,然后在令牌客户端构建中有var tokenClient=new TokenClientdisco.TokenEndpoint,mvc,secret 您的客户ID不正确。这个mvc来自哪里
public static List<TestUser> GetUsers()
{
return new List<TestUser>
{
new TestUser
{
SubjectId = "1",
Username = "admin",
Password = "admin",
Claims = new List<Claim>
{
new Claim("Name", "test")
}
}
};
}
var disco = DiscoveryClient.GetAsync("https://localhost:44327").Result;
var tokenClient = new TokenClient(disco.TokenEndpoint, "mvc", "secret");
var tokenResponse = tokenClient.RequestResourceOwnerPasswordAsync("api1","admin","admin").Result;
if (tokenResponse.IsError)
{
Console.WriteLine(tokenResponse.Error);
return;
}
var client = new HttpClient();
client.SetBearerToken(tokenResponse.AccessToken);
var res = client.GetAsync(disco.UserInfoEndpoint).Result;
var claims = res.Content;