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
Exemplo n.º 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);
        }
Exemplo n.º 2
0
 public async Task GetTokenByPinAsync_WithPinNull_ThrowsArgumentNullException()
 {
     var client = new ImgurClient("123", "1234");
     var endpoint = new OAuth2Endpoint(client);
     await endpoint.GetTokenByPinAsync(null);
 }
        public async Task GetTokenByPinAsync_WithClientSecretNull_ThrowsArgumentNullException()
        {
            var client = new ImgurClient("123");
            var endpoint = new OAuth2Endpoint(client);

            var exception =
                await
                    Record.ExceptionAsync(
                        async () => await endpoint.GetTokenByPinAsync("1234").ConfigureAwait(false))
                        .ConfigureAwait(false);
            Assert.NotNull(exception);
            Assert.IsType<ArgumentNullException>(exception);

            var argNullException = (ArgumentNullException) exception;
            Assert.Equal(argNullException.ParamName, "ClientSecret");
        }
        public async Task GetTokenByPinAsync_WithPinNull_ThrowsArgumentNullException()
        {
            var client = new ImgurClient("123", "1234");
            var endpoint = new OAuth2Endpoint(client);

            var exception =
                await
                    Record.ExceptionAsync(
                        async () => await endpoint.GetTokenByPinAsync(null).ConfigureAwait(false))
                        .ConfigureAwait(false);
            Assert.NotNull(exception);
            Assert.IsType<ArgumentNullException>(exception);
        }
        public async Task GetTokenByPinAsync_Equal()
        {
            var mockUrl = "https://api.imgur.com/oauth2/token";
            var mockResponse = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(MockOAuth2EndpointResponses.GetTokenByPin)
            };

            var client = new ImgurClient("123", "1234");
            var endpoint = new OAuth2Endpoint(client, new HttpClient(new MockHttpMessageHandler(mockUrl, mockResponse)));
            var token = await endpoint.GetTokenByPinAsync("4839").ConfigureAwait(false);

            Assert.Equal("PinResponse", token.AccessToken);
            Assert.Equal("2132d34234jkljj84ce0c16fjkljfsdfdc70", token.RefreshToken);
            Assert.Equal("bearer", token.TokenType);
            Assert.Equal(2419200, token.ExpiresIn);
            Assert.Equal("Bob", token.AccountUsername);
            Assert.Equal("45344", token.AccountId);
        }