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

GetTokenByPinAsync() public method

After the user authorizes, they will receive a PIN code that they copy into your app.
/// 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 GetTokenByPinAsync ( string pin ) : Task
pin string The PIN that the user is prompted to enter.
return Task
        public async Task<IOAuth2Token> GetTokenByPinAsync(string pin)
        {
            if (string.IsNullOrWhiteSpace(pin))
                throw new ArgumentNullException(nameof(pin));

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

            IOAuth2Token token;

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

            return token;
        }

Usage Example

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

            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));
            var token = await endpoint.GetTokenByPinAsync("4839");

            Assert.AreEqual("PinResponse", token.AccessToken);
            Assert.AreEqual("2132d34234jkljj84ce0c16fjkljfsdfdc70", token.RefreshToken);
            Assert.AreEqual("bearer", token.TokenType);
            Assert.AreEqual(2419200, token.ExpiresIn);
            Assert.AreEqual("Bob", token.AccountUsername);
            Assert.AreEqual("45344", token.AccountId);
        }
All Usage Examples Of Imgur.API.Endpoints.Impl.OAuth2Endpoint::GetTokenByPinAsync