public static async Task <AuthenticationResult> GetToken(string uniqueUserId = "") { // TODO: need to ensure that the unique user id part is included in the token cache var tokenCache = TokenCacheFactory.GetTokenCache(); OAuthToken token = tokenCache.GetToken(); // if there's a token but it's expired; we need to use the refresh token to get a new one if (token?.Expired() == true) { ExactOnlineClient client = GetClient(); token.AccessToken = client.GetCurrentToken(token.RefreshToken); token.ExpiresOnUtcTicks = client.ExpiresAt.Ticks; tokenCache.CacheToken(token); } AuthenticationResult authResult = ConvertAuthenticationResult(token, tokenCache); return(await Task.FromResult(authResult)); }