GetActiveUserToken() 공개 정적인 메소드

Gets the token that belongs to the current active config. This value will be normally be cached as the current active user config is normally cached. If refresh is true or if the current token already expired, however, we will refresh the active user config to get a new token.
public static GetActiveUserToken ( CancellationToken cancellationToken, bool refresh = false ) : Task
cancellationToken System.Threading.CancellationToken
refresh bool
리턴 Task
예제 #1
0
        /// <summary>
        /// Asynchronously revokes the token by calling
        /// <see cref="Google.Apis.Auth.OAuth2.Flows.IAuthorizationCodeFlow.RevokeTokenAsync"/>.
        /// </summary>
        /// <param name="taskCancellationToken">Cancellation token to cancel an operation.</param>
        /// <returns><c>true</c> if the token was revoked successfully.</returns>
        public async Task <bool> RevokeTokenAsync(CancellationToken taskCancellationToken)
        {
            TokenResponse userToken = await ActiveUserConfig.GetActiveUserToken(taskCancellationToken);

            await flow.RevokeTokenAsync("userId", userToken.AccessToken, taskCancellationToken).ConfigureAwait(false);

            // We don't set the token to null, cause we want that the next request (without reauthorizing) will fail).
            return(true);
        }
예제 #2
0
        /// <summary>
        /// Refreshes the token by calling to ActiveUserConfig.GetActiveUserToken
        /// </summary>
        public async Task <bool> RefreshTokenAsync(CancellationToken taskCancellationToken)
        {
            TokenResponse userToken = await ActiveUserConfig.GetActiveUserToken(taskCancellationToken, refresh : true);

            if (userToken != null && userToken.AccessToken != null)
            {
                return(true);
            }
            return(false);
        }
예제 #3
0
        public virtual async Task <string> GetAccessTokenForRequestAsync(string authUri = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            TokenResponse token = await ActiveUserConfig.GetActiveUserToken(cancellationToken);

            return(token.AccessToken);
        }