use of com.auth0.json.mgmt.client.Client in project auth0-java-mvc-common by auth0.
the class RequestProcessorTest method shouldSetMaxAgeIfProvided.
@Test
public void shouldSetMaxAgeIfProvided() {
AuthAPI client = new AuthAPI("me.auth0.com", "clientId", "clientSecret");
when(verifyOptions.getMaxAge()).thenReturn(906030);
RequestProcessor handler = new RequestProcessor.Builder(client, "code", verifyOptions).build();
HttpServletRequest request = new MockHttpServletRequest();
AuthorizeUrl builder = handler.buildAuthorizeUrl(request, response, "https://redirect.uri/here", "state", "nonce");
String authorizeUrl = builder.build();
assertThat(authorizeUrl, is(notNullValue()));
assertThat(authorizeUrl, containsString("max_age=906030"));
}
use of com.auth0.json.mgmt.client.Client in project auth0-java-mvc-common by auth0.
the class RequestProcessorTest method shouldNotSetNonceIfRequestTypeIsNotIdToken.
@Test
public void shouldNotSetNonceIfRequestTypeIsNotIdToken() {
AuthAPI client = new AuthAPI("me.auth0.com", "clientId", "clientSecret");
RequestProcessor handler = new RequestProcessor.Builder(client, "code", verifyOptions).build();
HttpServletRequest request = new MockHttpServletRequest();
AuthorizeUrl builder = handler.buildAuthorizeUrl(request, response, "https://redirect.uri/here", "state", "nonce");
String authorizeUrl = builder.build();
assertThat(authorizeUrl, is(notNullValue()));
assertThat(authorizeUrl, not(containsString("nonce=nonce")));
}
use of com.auth0.json.mgmt.client.Client in project auth0-java-mvc-common by auth0.
the class RequestProcessorTest method shouldReturnTokensOnProcessIfCodeRequestPassesIdTokenVerification.
@Test
public void shouldReturnTokensOnProcessIfCodeRequestPassesIdTokenVerification() throws Exception {
doNothing().when(tokenVerifier).verify(eq("backIdToken"), eq(verifyOptions));
Map<String, Object> params = new HashMap<>();
params.put("code", "abc123");
params.put("state", "1234");
MockHttpServletRequest request = getRequest(params);
request.setCookies(new Cookie("com.auth0.state", "1234"));
TokenRequest codeExchangeRequest = mock(TokenRequest.class);
TokenHolder tokenHolder = mock(TokenHolder.class);
when(tokenHolder.getIdToken()).thenReturn("backIdToken");
when(tokenHolder.getAccessToken()).thenReturn("backAccessToken");
when(tokenHolder.getRefreshToken()).thenReturn("backRefreshToken");
when(codeExchangeRequest.execute()).thenReturn(tokenHolder);
when(client.exchangeCode("abc123", "https://me.auth0.com:80/callback")).thenReturn(codeExchangeRequest);
RequestProcessor handler = new RequestProcessor.Builder(client, "code", verifyOptions).withIdTokenVerifier(tokenVerifier).build();
Tokens tokens = handler.process(request, response);
verify(tokenVerifier).verify("backIdToken", verifyOptions);
verifyNoMoreInteractions(tokenVerifier);
assertThat(tokens, is(notNullValue()));
assertThat(tokens.getIdToken(), is("backIdToken"));
assertThat(tokens.getAccessToken(), is("backAccessToken"));
assertThat(tokens.getRefreshToken(), is("backRefreshToken"));
}
use of com.auth0.json.mgmt.client.Client in project auth0-java-mvc-common by auth0.
the class RequestProcessorTest method shouldSetNonceIfRequestTypeIsIdToken.
@Test
public void shouldSetNonceIfRequestTypeIsIdToken() {
AuthAPI client = new AuthAPI("me.auth0.com", "clientId", "clientSecret");
RequestProcessor handler = new RequestProcessor.Builder(client, "id_token", verifyOptions).build();
HttpServletRequest request = new MockHttpServletRequest();
AuthorizeUrl builder = handler.buildAuthorizeUrl(request, response, "https://redirect.uri/here", "state", "nonce");
String authorizeUrl = builder.build();
assertThat(authorizeUrl, is(notNullValue()));
assertThat(authorizeUrl, containsString("nonce=nonce"));
}
use of com.auth0.json.mgmt.client.Client in project auth0-java-mvc-common by auth0.
the class RequestProcessorTest method shouldReturnTokensOnProcessIfIdTokenCodeRequestPassesIdTokenVerification.
@Test
public void shouldReturnTokensOnProcessIfIdTokenCodeRequestPassesIdTokenVerification() throws Exception {
doNothing().when(tokenVerifier).verify(eq("frontIdToken"), eq(verifyOptions));
Map<String, Object> params = new HashMap<>();
params.put("code", "abc123");
params.put("state", "1234");
params.put("id_token", "frontIdToken");
params.put("expires_in", "8400");
params.put("token_type", "frontTokenType");
MockHttpServletRequest request = getRequest(params);
request.setCookies(new Cookie("com.auth0.state", "1234"));
TokenRequest codeExchangeRequest = mock(TokenRequest.class);
TokenHolder tokenHolder = mock(TokenHolder.class);
when(tokenHolder.getIdToken()).thenReturn("backIdToken");
when(tokenHolder.getExpiresIn()).thenReturn(4800L);
when(tokenHolder.getTokenType()).thenReturn("backTokenType");
when(codeExchangeRequest.execute()).thenReturn(tokenHolder);
when(client.exchangeCode("abc123", "https://me.auth0.com:80/callback")).thenReturn(codeExchangeRequest);
RequestProcessor handler = new RequestProcessor.Builder(client, "id_token code", verifyOptions).withIdTokenVerifier(tokenVerifier).build();
Tokens tokens = handler.process(request, response);
// Should not verify the ID Token twice
verify(tokenVerifier).verify("frontIdToken", verifyOptions);
verify(tokenVerifier, never()).verify("backIdToken", verifyOptions);
verifyNoMoreInteractions(tokenVerifier);
assertThat(tokens, is(notNullValue()));
assertThat(tokens.getIdToken(), is("frontIdToken"));
assertThat(tokens.getType(), is("frontTokenType"));
assertThat(tokens.getExpiresIn(), is(8400L));
}
Aggregations