/** * Returns a new {@link Builder}, initialized with the provided access token value. * * @param tokenValue the value of the access token * @return the {@link Builder} */ public static Builder withToken(String tokenValue) { return new Builder(tokenValue); }
/** * Returns a new {@link Builder}, initialized with the authorization code grant type. * * @return the {@link Builder} */ public static Builder authorizationCode() { return new Builder(AuthorizationGrantType.AUTHORIZATION_CODE); }
/** * Returns {@code true} if the Authorization Request succeeded, otherwise {@code false}. * * @return {@code true} if the Authorization Request succeeded, otherwise {@code false} */ public boolean statusOk() { return !this.statusError(); }
@Test public void constructorWhenRequiredArgsProvidedThenCreated() { OAuth2AuthorizationRequest authorizationRequest = request().build(); OAuth2AuthorizationResponse authorizationResponse = success().build(); OAuth2AuthorizationExchange authorizationExchange = new OAuth2AuthorizationExchange(authorizationRequest, authorizationResponse); assertThat(authorizationExchange.getAuthorizationRequest()).isEqualTo(authorizationRequest); assertThat(authorizationExchange.getAuthorizationResponse()).isEqualTo(authorizationResponse); } }
private OAuth2AuthorizationRequest.Builder createAuthorizationRequest() { return OAuth2AuthorizationRequest.authorizationCode() .authorizationUri("https://example.com/oauth2/authorize") .clientId("client-id-1234") .state("state-1234"); }
@Test(expected = IllegalArgumentException.class) public void buildSuccessResponseWhenErrorCodeIsSetThenThrowIllegalArgumentException() { OAuth2AuthorizationResponse.success(AUTH_CODE) .redirectUri(REDIRECT_URI) .state(STATE) .errorCode(ERROR_CODE) .build(); }
public static OAuth2AuthorizationExchange success() { OAuth2AuthorizationRequest request = TestOAuth2AuthorizationRequests.request().build(); OAuth2AuthorizationResponse response = TestOAuth2AuthorizationResponses.success().build(); return new OAuth2AuthorizationExchange(request, response); } }
@Test(expected = IllegalArgumentException.class) public void buildErrorResponseWhenRedirectUriIsNullThenThrowIllegalArgumentException() { OAuth2AuthorizationResponse.error(ERROR_CODE) .redirectUri(null) .state(STATE) .build(); }
@Test(expected = IllegalArgumentException.class) public void constructorWhenAuthorizationRequestIsNullThenThrowIllegalArgumentException() { new OAuth2AuthorizationExchange(null, success().build()); }
@Test(expected = IllegalArgumentException.class) public void constructorWhenAuthorizationResponseIsNullThenThrowIllegalArgumentException() { new OAuth2AuthorizationExchange(request().build(), null); }
public static OAuth2AuthorizationResponse.Builder success() { return OAuth2AuthorizationResponse.success("authorization-code") .state("state") .redirectUri("https://example.com/authorize/oauth2/code/registration-id"); }
public static OAuth2AuthorizationResponse.Builder error() { return OAuth2AuthorizationResponse.error("error") .redirectUri("https://example.com/authorize/oauth2/code/registration-id") .errorUri("https://example.com/error"); } }
@Override public Object getCredentials() { return this.accessToken != null ? this.accessToken.getTokenValue() : this.authorizationExchange.getAuthorizationResponse().getCode(); }
@Test(expected = IllegalArgumentException.class) public void buildSuccessResponseWhenAuthCodeIsNullThenThrowIllegalArgumentException() { OAuth2AuthorizationResponse.success(null) .redirectUri(REDIRECT_URI) .state(STATE) .build(); }
@Before public void setUp() throws Exception { this.clientRegistrationBuilder = clientRegistration() .clientAuthenticationMethod(ClientAuthenticationMethod.BASIC); this.authorizationRequest = request().build(); this.authorizationResponse = success().build(); this.authorizationExchange = new OAuth2AuthorizationExchange(this.authorizationRequest, this.authorizationResponse); }
/** * Returns a new {@link Builder}, initialized with the provided response * @param response the response to intialize the builder with * @return the {@link Builder} */ public static Builder withResponse(OAuth2AccessTokenResponse response) { return new Builder(response); }
/** * Returns a new {@link Builder}, initialized with the implicit grant type. * * @return the {@link Builder} */ public static Builder implicit() { return new Builder(AuthorizationGrantType.IMPLICIT); }