Ejemplo n.º 1
0
        public void GetTokenByCodeRequest_WithTokenNull_ThrowsArgumentNullException()
        {
            var client         = new ImgurClient("123", "1234");
            var requestBuilder = new OAuth2RequestBuilder();

            requestBuilder.GetTokenByCodeRequest("url", null, "clientId", "clientSecret");
        }
        public void GetTokenByCodeRequest_WithTokenNull_ThrowsArgumentNullException()
        {
            var requestBuilder = new OAuth2RequestBuilder();
            var exception      =
                Record.Exception(() => OAuth2RequestBuilder.GetTokenByCodeRequest("url", null, "clientId", "clientSecret"));

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

            var argNullException = (ArgumentNullException)exception;

            Assert.Equal(argNullException.ParamName, "code");
        }
Ejemplo n.º 3
0
        /// <summary>
        ///     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.
        /// </summary>
        /// <param name="code">The code from the query string.</param>
        /// <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>
        /// <returns></returns>
        private async Task <IOAuth2Token> GetTokenByCodeInternalAsync(string code)
        {
            IOAuth2Token token;

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

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

            var request = OAuth2RequestBuilder.GetTokenByCodeRequest("https://api.imgur.com/oauth2/token", "123code", "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=authorization_code&code=123code", expected);
        }
        public void GetTokenByCodeRequest_WithClientSecretNull_ThrowsArgumentNullException()
        {
            var requestBuilder = new OAuth2RequestBuilder();

            var exception =
                Record.Exception(
                    () =>
                    OAuth2RequestBuilder.GetTokenByCodeRequest("https://api.imgur.com/oauth2/token", "123code", "clientId",
                                                               null));

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

            var argNullException = (ArgumentNullException)exception;

            Assert.Equal(argNullException.ParamName, "clientSecret");
        }
Ejemplo n.º 6
0
        /// <summary>
        ///     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.
        /// </summary>
        /// <param name="code">The code from the query string.</param>
        /// <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>
        /// <returns></returns>
        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 = OAuth2RequestBuilder.GetTokenByCodeRequest(TokenEndpointUrl, code, ApiClient.ClientId,
                                                                         ApiClient.ClientSecret))
            {
                token = await SendRequestAsync <OAuth2Token>(request).ConfigureAwait(false);
            }

            return(token);
        }
Ejemplo n.º 7
0
        public void GetTokenByCodeRequest_WithClientSecretNull_ThrowsArgumentNullException()
        {
            var requestBuilder = new OAuth2RequestBuilder();

            requestBuilder.GetTokenByCodeRequest("https://api.imgur.com/oauth2/token", "123code", "clientId", null);
        }
Ejemplo n.º 8
0
        public void GetTokenByCodeRequest_WithClientIdNull_ThrowsArgumentNullException()
        {
            var requestBuilder = new OAuth2RequestBuilder();

            requestBuilder.GetTokenByCodeRequest("url", "123code", null, "secret");
        }