首页 > 解决方案 > 身份模型是否具有密码资源所有者流程的令牌自动刷新?

问题描述

当使用RequestResourceOwnerPasswordAsynca 的扩展时TokenClient,给定带有 a 的响应,refresh_token并且expires_in是否存在令牌缓存的默认内存实现?

access_token到期时(从缓存中自动逐出),令牌客户端可以使用刷新令牌来请求令牌。

还是我们必须推出自己的?

private async Task<string> GetToken(
    string clientId, string clientSecret, string username, string password)
{
    string tokenAddress = "https://api.example.com/oauth2/token";
    var tokenClient = new TokenClient(tokenAddress, clientId, clientSecret);
    var result = await tokenClient.RequestResourceOwnerPasswordAsync(username, password);

    // do we create a wrapper around the token client that will implement a cache and auto-refresh
    // so that the next call, with same arguments will return same result.AccessToken
    // if still within bounds of the TimeNow.AddSeconds(result.ExpiresIn) window

    return result.AccessToken;
}

标签: .net-coreidentityserver4

解决方案


推荐阅读