2016-09-16 76 views
1

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

 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() 

我想从邮差一个新的令牌:enter image description here

enter image description here

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。

UPDATE: 我得到它的工作做从邮递员POST,并填写相应的X WWW的形式,进行了urlencoded领域,但我还没有想出如何得到它的使用授权工作标签和Postman的“获取新访问令牌”功能。不能用于从IdentityServer3获取令牌吗?

回答

0

我有它的工作,但不使用邮递员的“获取新访问令牌”功能。我无法弄清楚为什么这不起作用:p我只是发布到令牌URL,它给了我一个访问令牌,然后我可以在随后的调用中使用它。

POST:https://开头{{服务器}} /连接/令牌 CLIENT_ID: client_secret: grant_type:client_credentials 范围:

然后用它在你的服务器调用以下内容添加到你的头:

授权:承载[的access_token]

2

的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" 
    } 
} 

,这里是我设置从邮差

Get New Access Token Popup in Postman Desktop

不是对话框中的URL请求的方式。系统不是很宽容,如果你的网址错误,当你提出请求时你可能会看到一个完全错误的CORS错误。

+0

我将回调URL添加到客户端的重定向uris。我将我的令牌名称更新为“承载者”。我将Auth网址更改为授权终点。 (我的授权类型仍然是Client Credentials)。我在本地检查了请求访问令牌复选框,并且仍然使用此方法得到“invalid_client”...客户端是否必须使用“授权码”流设置? –

+0

我已经使用客户端证书和资源代码来完成它的工作。唯一的区别是资源代码邮差会弹出一个登录对话框。这对于我工作的开发很方便,因为大量REST服务调用需要与特定用户关联。 – GlennSills