【发布时间】:2017-02-02 01:11:26
【问题描述】:
我是身份服务器的新手,我的理解中缺少一个关键概念。 我正在使用来自MVC tutorial 的代码。
如果我用属性 [Authorize] 装饰我的 Home 控制器并访问我的网站,我会重定向到 IdentityServer。然后我使用我的用户名和密码登录。然后我使用一些自定义代码并进行身份验证。我取回一个 AccessToken,然后我可以访问 Home 控制器。
我的客户端设置如下:
new Client {
ClientId = "mvc",
ClientName = "MVC Client",
AllowedGrantTypes = GrantTypes.HybridAndClientCredentials,
ClientSecrets = new List<Secret>{new Secret("secret".Sha256())},
RequireConsent = false,
AccessTokenLifetime = 1,
// where to redirect to after login
RedirectUris = new List<string>{"http://localhost:5002/signin-oidc"},
// where to redirect to after logout
PostLogoutRedirectUris = new List<string>{"http://localhost:5002"},
AllowedScopes = new List<string>
{
StandardScopes.OpenId.Name,
StandardScopes.Profile.Name,
StandardScopes.OfflineAccess.Name,
}
}
我的访问令牌是
{
"nbf": 1474697839,
"exp": 1474697840,
"iss": "http://localhost:5000",
"aud": "http://localhost:5000/resources",
"client_id": "mvc",
"scope": [
"openid",
"profile"
],
"sub": "26296",
"auth_time": 1474697838,
"idp": "local",
"amr": [
"pwd"
]
}
当我将我的AccessTokenLifetime 设置为 1 时,我的令牌在发送以调用 API 等时将无效。不过,我仍然可以访问该网站。
让 MVC 网站确认我的令牌未过期的最佳方法是什么?这可能是刷新令牌发挥作用的地方。
注意
AccessTokenLifetime 设置为 1 仅用于测试,以便我可以快速测试。
【问题讨论】:
标签: asp.net-mvc identityserver4