Beispiel #1
0
        public void GetTokenByPinRequest_WithEndpointUrlNull_ThrowsArgumentNullException()
        {
            var client         = new ImgurClient("123", "1234");
            var requestBuilder = new OAuth2RequestBuilder();

            requestBuilder.GetTokenByPinRequest(null, "123", "clientId", "clientSecret");
        }
        public void GetTokenByPinRequest_WithClientSecretNull_ThrowsArgumentNullException()
        {
            var requestBuilder = new OAuth2RequestBuilder();

            var exception = Record.Exception(() => OAuth2RequestBuilder.GetTokenByPinRequest("url", "123", "clientId", null));

            Assert.NotNull(exception);
            Assert.IsType <ArgumentNullException>(exception);

            var argNullException = (ArgumentNullException)exception;

            Assert.Equal(argNullException.ParamName, "clientSecret");
        }
Beispiel #3
0
        /// <summary>
        ///     After the user authorizes, they will receive a PIN code that they copy into your app.
        /// </summary>
        /// <param name="pin">The PIN that the user is prompted to enter.</param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException">
        ///     Thrown when a null reference is passed to a method that does not accept it as a
        ///     valid argument.
        /// </exception>
        /// <exception cref="ImgurException">Thrown when an error is found in a response from an Imgur endpoint.</exception>
        /// <exception cref="MashapeException">Thrown when an error is found in a response from a Mashape endpoint.</exception>
        private async Task <IOAuth2Token> GetTokenByPinInternalAsync(string pin)
        {
            IOAuth2Token token;

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

            return(token);
        }
        public async Task GetTokenByPinRequest_WithPinEqual()
        {
            var requestBuilder = new OAuth2RequestBuilder();

            var request = OAuth2RequestBuilder.GetTokenByPinRequest("https://api.imgur.com/oauth2/token", "4899", "123",
                                                                    "1234");

            Assert.NotNull(request);
            Assert.Equal("https://api.imgur.com/oauth2/token", request.RequestUri.ToString());
            Assert.Equal(HttpMethod.Post, request.Method);
            Assert.NotNull(request.Content);

            var expected = await request.Content.ReadAsStringAsync().ConfigureAwait(false);

            Assert.Equal("client_id=123&client_secret=1234&grant_type=pin&pin=4899", expected);
        }
Beispiel #5
0
        /// <summary>
        ///     After the user authorizes, they will receive a PIN code that they copy into your app.
        /// </summary>
        /// <param name="pin">The PIN that the user is prompted to enter.</param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException">
        ///     Thrown when a null reference is passed to a method that does not accept it as a
        ///     valid argument.
        /// </exception>
        /// <exception cref="ImgurException">Thrown when an error is found in a response from an Imgur endpoint.</exception>
        /// <exception cref="MashapeException">Thrown when an error is found in a response from a Mashape endpoint.</exception>
        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 = OAuth2RequestBuilder.GetTokenByPinRequest(TokenEndpointUrl, pin, ApiClient.ClientId,
                                                                        ApiClient.ClientSecret))
            {
                token = await SendRequestAsync <OAuth2Token>(request).ConfigureAwait(false);
            }

            return(token);
        }