【发布时间】:2022-01-02 03:18:19
【问题描述】:
我刚开始使用 identityserver4,无法弄清楚为什么用户信息端点返回了禁止状态
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,
}
};
}.
我的用户:
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;
为什么我在 userinfo 端点中得到一个禁止的状态码? 任何帮助表示赞赏。
【问题讨论】:
标签: c# identityserver4