Home > OS >  Is there a possibility to set RefreshTokenUsage in oidc client?
Is there a possibility to set RefreshTokenUsage in oidc client?

Time:05-02

i have a problem with my token. when we start our program, the cache should be checked for a valid token. This works for the first time, but afterwards refreshToken.isError is always true, even when the token should not be expired yet. I found this page https://identityserver4.readthedocs.io/en/latest/topics/refresh_tokens.html but i cant find a way to set RefreshTokenUsage. If anyone has an idea how this problem could be fixed, that would be very helpful.

Here is the method:

      private async Task<string?> TryGetTokenFromCache()
    {
        StatusChangeEvent?.InvokeRetrievingTokenFromCache();
        var existingToken = _dataProtection.Unprotect(_cacheFilePath);
        if (existingToken != null)
        {
            var token = System.Text.Encoding.Default.GetString(existingToken);
            if (!string.IsNullOrEmpty(token))
            {
                var refreshTokenResult = await _client.RefreshTokenAsync(token);
                if (!refreshTokenResult.IsError)
                {
                    StatusChangeEvent?.InvokeLoggedIn();
                    return refreshTokenResult.AccessToken;
                }
            }
        }

        return null;
    }

CodePudding user response:

Solution: We did not set the new refresh token in the cache file. We just had to write the new refreshtoken to the cache file when result is not error.

  • Related