public MemoryCache CreateInstance(AuthorizationCodeResp token) { var memoryCache = new MemoryCache(new MemoryCacheOptions()); memoryCache.Set(token.AccessToken, token); return(memoryCache); }
public void SaveToken(AuthorizationCodeResp token) { using (var writer = new StreamWriter(tokenFilePath, false)) { var json = JsonConvert.SerializeObject(token); writer.Write(json); } }
/// <summary> /// Methode use to refresh a token /// </summary> /// <param name="refreshToken">token which was returned as refresh token</param> public async Task <Result <AuthorizationCodeResp> > RefreshAccessToken(AuthorizationCodeResp refreshToken) { var clientAssertion = GetClientAssertion(); var auth = await apiClient.PostFormDataAsync <AuthorizationCodeResp>("/auth/token", new List <KeyValuePair <string, string> > { new KeyValuePair <string, string>("grant_type", "refresh_token"), new KeyValuePair <string, string>("refresh_token", refreshToken.RefreshToken), new KeyValuePair <string, string>("client_id", revolutApiSettings.AccountId), new KeyValuePair <string, string>("client_assertion_type", "urn:ietf:params:oauth:client-assertion-type:jwt-bearer"), new KeyValuePair <string, string>("client_assertion", clientAssertion) }); return(auth); }
private async Task <string> RefreshTokenAsync(AuthorizationCodeResp accessToken) { var response = await authorizationApiClient.RefreshAccessToken(accessToken); if (!response.Success) { throw new ApplicationException("Token Cannot be refreshed"); } var newToken = response.Value; newToken.RefreshToken = accessToken.RefreshToken; newToken.ExpirationDate = DateTime.Now.AddSeconds(newToken.ExpiresIn); memoryCache.Set(newToken.AccessToken, newToken, ComputeNextExpireIn(newToken.ExpiresIn)); memoryCache.Remove(accessToken.AccessToken); accessToken.AccessToken = newToken.AccessToken; accessToken.ExpirationDate = newToken.ExpirationDate; return(newToken.AccessToken); }