我一直在玩弄Thinktecture的身份服务器,现在我在试图到达刷新令牌端点时遇到了一些问题。
我有几个客户端配置成这样:
授权码流客户端:
新客户
{
ClientId = "tripgalleryauthcode",
ClientName = "Trip Gallery (Authorization Code)",
Flow = Flows.AuthorizationCode,
AllowAccessToAllScopes = true,
RequireConsent = false,
RedirectUris = new List<string>
{
"redirecturi"
},
ClientSecrets = new List<Secret>()
{
new Secret("somesecret".Sha256())
}
}
混合流客户端:
new Client
{
ClientId = "tripgalleryhybrid",
ClientName = "Tripgalleryhybrid (Hybrid)",
Flow = Flows.Hybrid,
AllowAccessToAllScopes = true,
RequireConsent = false,
IdentityTokenLifetime = 10,
AccessTokenLifetime = 120,
// redirect = URI of the MVC application
RedirectUris = new List<string>
{
"redirecturi"
},
// Needed when requesting refresh tokens
ClientSecrets = new List<Secret>()
{
new Secret("somesecret".Sha256())
},
PostLogoutRedirectUris = new List<string>()
{
"postlogouturi"
}
}
我所做的是,我有ASP.NET MVC客户端,它使用混合流程。身份验证之后,我将接收访问令牌、刷新令牌和其他一些内容。
我要做的是测试刷新令牌端点。我准备请求的方式如下:
我在请求的标题中向:/identity/connect/revocation发出了POST请求:
在我拥有的请求正文中:token=0a24f80dcc97a56ede0e7c04563a3493&token_type_hint=refresh_token
令牌是在我通过混合客户端进行身份验证之后出现的。
当我触发请求时,它会返回Http 200。但是没有返回任何内容。当我进入Identity Server日志时,我看到的是:
SnapshotHelper::TakeSnapshotTimerCallback
SnapshotHelper::TakeSnapshotInternal - no new files in CodeGen
w3wp.exe Warning: 0 : 2016-11-13 13:54:11.557 +00:00 [Warning] AuthorizationCodeStore not configured - falling back to InMemory
w3wp.exe Warning: 0 : 2016-11-13 13:54:11.620 +00:00 [Warning] TokenHandleStore not configured - falling back to InMemory
w3wp.exe Warning: 0 : 2016-11-13 13:54:11.620 +00:00 [Warning] ConsentStore not configured - falling back to InMemory
w3wp.exe Warning: 0 : 2016-11-13 13:54:11.620 +00:00 [Warning] RefreshTokenStore not configured - falling back to InMemory
w3wp.exe Information: 0 : 2016-11-13 13:54:12.356 +00:00 [Information] Start token revocation request
w3wp.exe Information: 0 : 2016-11-13 13:54:12.401 +00:00 [Information] Client secret id found: "tripgalleryauthcode"
w3wp.exe Information: 0 : 2016-11-13 13:54:12.401 +00:00 [Information] Client validation success
w3wp.exe Information: 0 : 2016-11-13 13:54:12.401 +00:00 [Information] End token revocation request
我真正期望的是至少获得新的访问和刷新令牌,但什么都没有。我想我真的错过了一些在我的客户配置,所以我会非常高兴,如果你能帮助我。
编辑:
我将端点更改为:/identity/connect/token,也将请求体更改为:grant_type=refresh_token&token=635c7cbcfa1c0417b6d574ade388c0d8&token_type_hint=refresh_token,但仍然没有成功。现在我的身份服务器日志上写着:
SnapshotHelper::TakeSnapshotTimerCallback
SnapshotHelper::TakeSnapshotInternal - no new files in CodeGen
SnapshotHelper::TakeSnapshot time since last: 00:19:59.9992231
w3wp.exe Information: 0 : 2016-11-13 20:40:33.406 +00:00 [Information] Start token request
w3wp.exe Information: 0 : 2016-11-13 20:40:33.406 +00:00 [Information] Client secret id found: "tripgalleryauthcode"
w3wp.exe Information: 0 : 2016-11-13 20:40:33.406 +00:00 [Information] Client validation success
w3wp.exe Information: 0 : 2016-11-13 20:40:33.406 +00:00 [Information] Start token request validation
w3wp.exe Information: 0 : 2016-11-13 20:40:33.406 +00:00 [Information] Start validation of refresh token request
w3wp.exe Error: 0 : 2016-11-13 20:40:33.406 +00:00 [Error] "Refresh token is missing"
"{
\"ClientId\": \"tripgalleryauthcode\",
\"ClientName\": \"Trip Gallery (Authorization Code)\",
\"GrantType\": \"refresh_token\",
\"Raw\": {
\"grant_type\": \"refresh_token\",
\"token\": \"635c7cbcfa1c0417b6d574ade388c0d8\",
\"token_type_hint\": \"refresh_token\"
}
}"
w3wp.exe Information: 0 : 2016-11-13 20:40:33.406 +00:00 [Information] End token request
w3wp.exe Information: 0 : 2016-11-13 20:40:33.406 +00:00 [Information] Returning error: invalid_request
第二次编辑:
基于此处发布的文档:令牌端点及其内部的内容:TokenRequest和更多与此相关的资源:
我相信这是正确的。不幸的是,我仍然从身份服务器获得HTTP400,错误是:error=invalid_grant.这使我认为,我很可能不得不对我的客户做一些更多的配置。在互联网上的一些示例中,我可以看到在配置客户机时使用:AbsoluteRefreshTokenLifetime,SlidingRefreshTokenLifetime、RefreshTokenUsage、RefreshTokenExpiration。你能至少给我一个方向吗?
解决方案:
对我起作用的是将这些选项添加到客户端: //刷新令牌选项
AccessTokenType = AccessTokenType.Jwt,
AccessTokenLifetime = 3600,
RefreshTokenUsage = TokenUsage.ReUse,
RefreshTokenExpiration = TokenExpiration.Absolute,
AbsoluteRefreshTokenLifetime = 1296000
发布于 2016-11-13 18:32:05
您正在使用吊销端点,它允许您销毁(也称为"revoke")一个令牌。要使用刷新令牌获得新的访问令牌,您需要使用grant_type=refresh_token的令牌端点,如docs:https://identityserver.github.io/Documentation/docsv2/endpoints/token.html中所述。
https://stackoverflow.com/questions/40575185
复制相似问题