【发布时间】:2018-07-14 15:17:33
【问题描述】:
我已经设置了一个在 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()
IdentityServer 正在测试服务器上运行,这就是我没有选择“本地请求访问令牌”的原因。
当我点击“请求令牌”时,我收到以下错误记录:
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
我不太确定为什么验证器无法验证秘密。它以 Sha256 的形式保存在数据库中,IdentityServer 可以解析和验证 Sha256。
更新: 我让它工作从邮递员做一个 POST 并填写适当的 x-www-form-urlencoded 字段,但我仍然没有弄清楚如何使用授权选项卡和“获取新访问令牌”功能让它工作邮递员。不能用来从 IdentityServer3 获取访问令牌吗?
【问题讨论】:
标签: c# oauth-2.0 identityserver3