C# IdentityServer3邮递员客户端无效

C# IdentityServer3邮递员客户端无效,c#,oauth-2.0,identityserver3,C#,Oauth 2.0,Identityserver3,我已经设置了一个在IIS中运行的IdentityServer3实例 var validators = new List<Registration<ISecretValidator>> { new Registration<ISecretValidator, HashedSharedSecretValidator>(), new Registration<ISecretVali

我已经设置了一个在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
                }
            });
        });
我想从邮递员那里得到一个新的代币:

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

更新:
我从Postman那里得到了一篇文章,并填写了相应的x-www-form-urlencoded字段,但我仍然没有找到如何使用Postman的授权选项卡和“获取新访问令牌”功能使其工作的方法。这不能用于从IdentityServer3获取访问令牌吗?

我已经让它工作了,但没有使用Postman的“获取新访问令牌”功能。我不明白为什么这样做不起作用:p相反,我只是发布到令牌URL,它给了我一个访问令牌,然后我就可以在随后的服务调用中使用它

POST: https://{{server}}/connect/token
client_id:
client_secret:
grant_type: client_credentials
scope:
然后,要在服务器调用中使用它,请将以下内容添加到标头中:


授权:承载者[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"
    }
}
新客户端
{
ClientId=“postmantestclient”,
ClientName=“邮递员http测试客户端”,
Flow=Flows.AuthorizationCode,
AllowAccessToAllScopes=true,
IdentityTokenLifetime=60*60*24,
AccessTokenLifetime=60*60*24,
RequireSent=false,
ClientSecrets=新列表
{
新秘密(“postansecret.Sha256())
},
重定向URI=新列表()
{
"https://www.getpostman.com/oauth2/callback"
}
}
这是我设置邮递员请求的方式


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

我将回调URL添加到客户端的重定向URI中。我将我的令牌名称更新为“持有者”。我将Auth url更改为authorize端点。(我的授权类型仍然是客户端凭据)。我选中了“本地请求访问令牌”复选框,但仍然使用此方法获取“无效的\u客户端”。。。客户端是否必须使用“授权代码”流进行设置?我已经使用客户端凭据和资源代码使其工作。唯一的区别是,邮递员会弹出一个登录对话框。这对于我工作的开发来说很方便,因为许多REST服务调用需要和特定用户关联。
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"
    }
}