use of com.auth0.client.auth.AuthAPI 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.client.auth.AuthAPI 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.client.auth.AuthAPI in project auth0-java-mvc-common by auth0.
the class RequestProcessorTest method shouldBuildAuthorizeUrl.
@Test
public void shouldBuildAuthorizeUrl() {
AuthAPI client = new AuthAPI("me.auth0.com", "clientId", "clientSecret");
SignatureVerifier signatureVerifier = mock(SignatureVerifier.class);
IdTokenVerifier.Options verifyOptions = new IdTokenVerifier.Options("issuer", "audience", signatureVerifier);
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, CoreMatchers.startsWith("https://me.auth0.com/authorize?"));
assertThat(authorizeUrl, containsString("client_id=clientId"));
assertThat(authorizeUrl, containsString("redirect_uri=https://redirect.uri/here"));
assertThat(authorizeUrl, containsString("response_type=code"));
assertThat(authorizeUrl, containsString("scope=openid"));
assertThat(authorizeUrl, containsString("state=state"));
assertThat(authorizeUrl, not(containsString("max_age=")));
assertThat(authorizeUrl, not(containsString("nonce=nonce")));
assertThat(authorizeUrl, not(containsString("response_mode=form_post")));
}
use of com.auth0.client.auth.AuthAPI in project auth0-java-mvc-common by auth0.
the class RequestProcessorTest method shouldBuildAuthorizeUrlWithNonceAndFormPostIfResponseTypeIsIdToken.
@Test
public void shouldBuildAuthorizeUrlWithNonceAndFormPostIfResponseTypeIsIdToken() {
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, CoreMatchers.startsWith("https://me.auth0.com/authorize?"));
assertThat(authorizeUrl, containsString("client_id=clientId"));
assertThat(authorizeUrl, containsString("redirect_uri=https://redirect.uri/here"));
assertThat(authorizeUrl, containsString("response_type=id_token"));
assertThat(authorizeUrl, containsString("scope=openid"));
assertThat(authorizeUrl, containsString("state=state"));
assertThat(authorizeUrl, containsString("nonce=nonce"));
assertThat(authorizeUrl, containsString("response_mode=form_post"));
}
use of com.auth0.client.auth.AuthAPI in project CollectiveOneWebapp by CollectiveOne.
the class TestElementOrder method setUp.
@SuppressWarnings("serial")
@Before
public void setUp() throws Exception {
AuthAPI auth = new AuthAPI(auth0Domain, clientId, clientSecret);
AuthRequest request = auth.login(testEmail1, testPwd1).setScope("openid contacts");
try {
TokenHolder holder = request.execute();
authorizationTokenUser1 = holder.getIdToken();
} catch (APIException exception) {
System.out.println(exception);
} catch (Auth0Exception exception) {
System.out.println(exception);
}
MvcResult result = this.mockMvc.perform(get("/1/user/myProfile").header("Authorization", "Bearer " + authorizationTokenUser1)).andReturn();
assertEquals("error in http request: " + result.getResponse().getErrorMessage(), 200, result.getResponse().getStatus());
GetResult<AppUserDto> getResultUser = gson.fromJson(result.getResponse().getContentAsString(), new TypeToken<GetResult<AppUserDto>>() {
}.getType());
user1 = getResultUser.getData();
logger.debug("Test user created:" + result.getResponse().getContentAsString());
request = auth.login(testEmail2, testPwd2).setScope("openid contacts");
try {
TokenHolder holder = request.execute();
authorizationTokenUser2 = holder.getIdToken();
} catch (APIException exception) {
System.out.println(exception);
} catch (Auth0Exception exception) {
System.out.println(exception);
}
result = this.mockMvc.perform(get("/1/user/myProfile").header("Authorization", "Bearer " + authorizationTokenUser2)).andReturn();
assertEquals("error in http request: " + result.getResponse().getErrorMessage(), 200, result.getResponse().getStatus());
getResultUser = gson.fromJson(result.getResponse().getContentAsString(), new TypeToken<GetResult<AppUserDto>>() {
}.getType());
user2 = getResultUser.getData();
logger.debug("Test user created: " + result.getResponse().getContentAsString());
/**
* create initiative
*/
NewInitiativeDto initiativeDto = new NewInitiativeDto(initiativeName, "");
MemberDto member = new MemberDto();
member.setRole("ADMIN");
member.setUser(user1);
initiativeDto.getMembers().add(member);
result = this.mockMvc.perform(post("/1/initiative/create").header("Authorization", "Bearer " + authorizationTokenUser1).contentType(MediaType.APPLICATION_JSON).content(gson.toJson(initiativeDto))).andReturn();
assertEquals("error in http request: " + result.getResponse().getErrorMessage(), 200, result.getResponse().getStatus());
PostResult postResult = gson.fromJson(result.getResponse().getContentAsString(), PostResult.class);
initiativeId = postResult.getElementId();
logger.debug("Initiative created: " + initiativeId);
result = this.mockMvc.perform(get("/1/initiative/" + initiativeId).header("Authorization", "Bearer " + authorizationTokenUser1)).andReturn();
GetResult<InitiativeDto> getResultInit = gson.fromJson(result.getResponse().getContentAsString(), new TypeToken<GetResult<InitiativeDto>>() {
}.getType());
initiative = getResultInit.getData();
logger.debug("Initiative retrieved: " + result.getResponse().getContentAsString());
}
Aggregations