public void GetTokenByRefreshTokenRequest_WithTokenNull_ThrowsArgumentNullException() { var client = new ImgurClient("123", "1234"); var requestBuilder = new OAuth2RequestBuilder(); requestBuilder.GetTokenByRefreshTokenRequest("url", null, "clientId", "clientSecret"); }
/// <summary> /// If a user has authorized their account but you no longer have a valid access_token for them, /// then a new one can be generated by using the refreshToken. /// <para> /// When your application receives a refresh token, it is important to store /// that refresh token for future use. /// </para> /// <para> /// If your application loses the refresh token, you will have to prompt the user /// for their login information again. /// </para> /// </summary> /// <param name="refreshToken">The refresh token.</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> GetTokenByRefreshTokenInternalAsync(string refreshToken) { IOAuth2Token token; using ( var request = OAuth2RequestBuilder.GetTokenByRefreshTokenRequest(TokenEndpointUrl, refreshToken, ApiClient.ClientId, ApiClient.ClientSecret)) { token = await SendRequestAsync <OAuth2Token>(request).ConfigureAwait(false); } return(token); }
public void GetTokenByRefreshTokenRequest_WithTokenNull_ThrowsArgumentNullException() { var requestBuilder = new OAuth2RequestBuilder(); var exception = Record.Exception( () => OAuth2RequestBuilder.GetTokenByRefreshTokenRequest("url", null, "clientId", "clientSecret")); Assert.NotNull(exception); Assert.IsType <ArgumentNullException>(exception); var argNullException = (ArgumentNullException)exception; Assert.Equal(argNullException.ParamName, "refreshToken"); }
public async Task GetTokenByRefreshTokenRequest_WithRefreshTokenEqual() { var requestBuilder = new OAuth2RequestBuilder(); var request = OAuth2RequestBuilder.GetTokenByRefreshTokenRequest("https://api.imgur.com/oauth2/token", "ABChjfhjhjdhfjksdfsdfsdfs", "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=refresh_token&refresh_token=ABChjfhjhjdhfjksdfsdfsdfs", expected); }
/// <summary> /// If a user has authorized their account but you no longer have a valid access_token for them, /// then a new one can be generated by using the refreshToken. /// <para> /// When your application receives a refresh token, it is important to store /// that refresh token for future use. /// </para> /// <para> /// If your application loses the refresh token, you will have to prompt the user /// for their login information again. /// </para> /// </summary> /// <param name="refreshToken">The refresh token.</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> GetTokenByRefreshTokenAsync(string refreshToken) { if (string.IsNullOrWhiteSpace(refreshToken)) { throw new ArgumentNullException(nameof(refreshToken)); } if (string.IsNullOrWhiteSpace(ApiClient.ClientSecret)) { throw new ArgumentNullException(nameof(ApiClient.ClientSecret)); } IOAuth2Token token; using ( var request = OAuth2RequestBuilder.GetTokenByRefreshTokenRequest(TokenEndpointUrl, refreshToken, ApiClient.ClientId, ApiClient.ClientSecret)) { token = await SendRequestAsync <OAuth2Token>(request).ConfigureAwait(false); } return(token); }
public void GetTokenByRefreshTokenRequest_WithEndpointUrlNull_ThrowsArgumentNullException() { var requestBuilder = new OAuth2RequestBuilder(); requestBuilder.GetTokenByRefreshTokenRequest(null, "ABChjfhjhjdhfjksdfsdfsdfs", "clientId", "clientSecret"); }