Imgur.API.Endpoints.Impl.OAuth2Endpoint.GetTokenByRefreshTokenAsync C# (CSharp) Method

GetTokenByRefreshTokenAsync() public method

If a user has authorized their account but you no longer have a valid access_token for them, then a new one can be generated by using the refreshToken.

When your application receives a refresh token, it is important to store that refresh token for future use.

If your application loses the refresh token, you will have to prompt the user for their login information again.

/// Thrown when a null reference is passed to a method that does not accept it as a /// valid argument. /// Thrown when an error is found in a response from an Imgur endpoint. Thrown when an error is found in a response from a Mashape endpoint.
public GetTokenByRefreshTokenAsync ( string refreshToken ) : Task
refreshToken string
return Task
        public async Task<IOAuth2Token> GetTokenByRefreshTokenAsync(string refreshToken)
        {
            if (string.IsNullOrWhiteSpace(refreshToken))
                throw new ArgumentNullException(nameof(refreshToken));

            if (string.IsNullOrWhiteSpace(ApiClient.ClientSecret))
                throw new ArgumentNullException(nameof(ApiClient.ClientSecret));

            IOAuth2Token token;

            using (
                var request = RequestBuilder.GetTokenByRefreshTokenRequest(TokenEndpointUrl, refreshToken,
                    ApiClient.ClientId, ApiClient.ClientSecret))
            {
                token = await SendRequestAsync<OAuth2Token>(request).ConfigureAwait(false);
            }

            return token;
        }
    }

Usage Example

Esempio n. 1
0
        private IOAuth2Token GetOAuth2Token()
        {
            if (_token != null)
                return _token;

            var authentication = new ImgurClient(ClientId, ClientSecret);
            var endpoint = new OAuth2Endpoint(authentication);
            _token = endpoint.GetTokenByRefreshTokenAsync(RefreshToken).Result;
            return _token;
        }
All Usage Examples Of Imgur.API.Endpoints.Impl.OAuth2Endpoint::GetTokenByRefreshTokenAsync