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

GetTokenByCodeAsync() public method

After the user authorizes, the pin is returned as a code to your application via the redirect URL you specified during registration, in the form of a regular query string parameter.
/// 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 GetTokenByCodeAsync ( string code ) : Task
code string The code from the query string.
return Task
        public async Task<IOAuth2Token> GetTokenByCodeAsync(string code)
        {
            if (string.IsNullOrWhiteSpace(code))
                throw new ArgumentNullException(nameof(code));

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

            IOAuth2Token token;

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

            return token;
        }

Usage Example

コード例 #1
0
        public async Task GetTokenByCodeAsync_ThrowsImgurException()
        {
            var fakeHttpMessageHandler = new FakeHttpMessageHandler();
            var fakeResponse = new HttpResponseMessage(HttpStatusCode.BadRequest)
            {
                Content = new StringContent(OAuth2EndpointResponses.OAuth2TokenResponseError)
            };

            fakeHttpMessageHandler.AddFakeResponse(new Uri("https://api.imgur.com/oauth2/token"), fakeResponse);

            var client = new ImgurClient("123", "1234");
            var endpoint = new OAuth2Endpoint(client, new HttpClient(fakeHttpMessageHandler));
            await endpoint.GetTokenByCodeAsync("12345");
        }
All Usage Examples Of Imgur.API.Endpoints.Impl.OAuth2Endpoint::GetTokenByCodeAsync