gpt4 book ai didi

c# - IdentityServer3 PostMan invalid_client

转载 作者:太空宇宙 更新时间:2023-11-03 23:10:09 25 4
gpt4 key购买 nike

我已经设置了一个在 IIS 中运行的 IdentityServer3 实例。

        var validators = new List<Registration<ISecretValidator>>
{
new Registration<ISecretValidator, HashedSharedSecretValidator>(),
new Registration<ISecretValidator, X509CertificateThumbprintSecretValidator>()
};

// .Register() is an extension method that setups that setups the
// IdentityServerServiceFactory
var factory = new EntityFrameworkServiceOptions()
.Register()
.UseInMemoryUsers(Users.Get());
factory.SecretValidators = validators;

app.Map($"/{IdentityServer.Path}", server =>
{
server.UseIdentityServer(new IdentityServerOptions()
{
RequireSsl = false,
SiteName = siteName,
SigningCertificate = Certificate.Load(),
Factory = factory,

// Currently does nothing. There are no plugins.
PluginConfiguration = ConfigurePlugins,
AuthenticationOptions = new AuthenticationOptions()
{
EnablePostSignOutAutoRedirect = true,

// Currently does nothing. There are no IdentityProviders setup
IdentityProviders = ConfigureIdentityProviders
}
});
});

我已经在 EF 数据库中为客户端凭证流设置了一个客户端。所以在 Client 表中有一个客户端,我已经让客户端访问 ClientScopes 表中的一个范围,并且我已经在ClientSecrets 表。

存储在数据库中的相关值是(所有未列出的值都是 IdentityServer3 默认值):

ClientId = 'client'
Flow = 'ClientCredentials [3]'
ClientScope = 'api'
ClientSecret = 'secret'.Sha256()

我正在尝试从 Postman 获取新 token :enter image description here

enter image description here

IdentityServer 正在测试服务器上运行,这就是为什么我没有选择“在本地请求访问 token ”。

当我点击“请求 token ”时,我记录了以下错误:

2016-09-16 16:18:28.470 -05:00 [Debug] Start client validation
2016-09-16 16:18:28.470 -05:00 [Debug] Start parsing Basic Authentication secret
2016-09-16 16:18:28.470 -05:00 [Debug] Parser found secret: "BasicAuthenticationSecretParser"
w3wp.exe Information: 0 : 2016-09-16 16:18:28.470 -05:00 [Information] Secret id found: "client"
2016-09-16 16:18:28.470 -05:00 [Debug] No matching hashed secret found.
w3wp.exe Information: 0 : 2016-09-16 16:18:28.470 -05:00 [Information] Secret validators could not validate secret
w3wp.exe Information: 0 : 2016-09-16 16:18:28.470 -05:00 [Information] Client validation failed.
w3wp.exe Information: 0 : 2016-09-16 16:18:28.470 -05:00 [Information] End token request
w3wp.exe Information: 0 : 2016-09-16 16:18:28.470 -05:00 [Information] Returning error: invalid_client

我不太确定为什么验证器无法验证 secret 。它作为 Sha256 保存在数据库中,IdentityServer 可以解析和验证 Sha256。

更新:我通过 Postman 发送 POST 并填写适当的 x-www-form-urlencoded 字段让它工作,但我仍然没有弄清楚如何使用授权选项卡和“获取新访问 token ”功能让它工作的 postman 。那不能用于从 IdentityServer3 获取访问 token 吗?

最佳答案

Postman 内置的对 OAuth2 token 的支持工作正常。您可以使用任一客户端。客户端凭据和授权代码授予类型都可以正常工作——如果您设置授权代码类型,如下所示,您甚至会看到一个弹出窗口,允许您输入用户名和密码。这是我用于授权代码流的客户端条目:

new Client
{
ClientId = "postmantestclient",
ClientName = "Postman http test client",
Flow = Flows.AuthorizationCode,
AllowAccessToAllScopes = true,
IdentityTokenLifetime = 60 * 60 * 24,
AccessTokenLifetime = 60 * 60 * 24,
RequireConsent = false,
ClientSecrets = new List<Secret>
{
new Secret("PostmanSecret".Sha256())
},
RedirectUris = new List<string>()
{
"https://www.getpostman.com/oauth2/callback"
}
}

这是我设置来自 Postman 的请求的方式

Get New Access Token Popup in Postman Desktop

不是对话框中的 URL。该系统不是很宽容,如果您的 URL 错误,您在发出请求时很可能会看到一个完全虚假的 CORS 错误。

关于c# - IdentityServer3 PostMan invalid_client,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39540463/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com