IdentityServer3 邮递员 invalid_client

IdentityServer3 PostMan invalid_client

我已经在 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 table 中有一个客户端,我已经让客户端访问 ClientScopes table 中的一个范围,并且我已经给了客户端一个秘密在 ClientSecrets table.

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

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

我正在尝试从 Postman 获取新令牌:

IdentityServer 运行 在测试服务器上,这就是我没有选择 "Request access token locally" 的原因。

当我点击 "Request 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

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

更新: 我从 Postman 那里做了一个 POST 并填写了适当的 x-www-form-urlencoded 字段,但我仍然没有弄清楚如何使用授权选项卡和 [=41 让它工作=] 邮递员的功能。那不能用于从 IdentityServer3 获取访问令牌吗?

我已经可以使用了,但没有使用 Postman 的 "Get New Access Token" 功能。我无法弄清楚为什么这不起作用 :p 相反,我只是发布到令牌 URL,它给了我一个访问令牌,然后我就可以在后续调用我的服务时使用它。

POST: https://{{server}}/connect/token
client_id:
client_secret:
grant_type: client_credentials
scope:

然后在您的服务器调用中使用它,将以下内容添加到您的 header:

授权:不记名 [access_token]

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

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 的请求的方式

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