use of javax.ws.rs.core.MultivaluedHashMap in project oxAuth by GluuFederation.
the class AuthorizationCodeFlowEmbeddedTest method revokeTokensStep4.
@Parameters({ "tokenPath" })
@Test(dependsOnMethods = { "dynamicClientRegistration", "revokeTokensStep2n3" })
public void revokeTokensStep4(final String tokenPath) throws Exception {
Builder request = ResteasyClientBuilder.newClient().target(url.toString() + tokenPath).request();
TokenRequest tokenRequest = new TokenRequest(GrantType.REFRESH_TOKEN);
tokenRequest.setRefreshToken(refreshToken1);
tokenRequest.setScope("email read_stream manage_pages");
tokenRequest.setAuthUsername(clientId);
tokenRequest.setAuthPassword(clientSecret);
request.header("Authorization", "Basic " + tokenRequest.getEncodedCredentials());
Response response = request.post(Entity.form(new MultivaluedHashMap<String, String>(tokenRequest.getParameters())));
String entity = response.readEntity(String.class);
showResponse("revokeTokensStep4", response, entity);
assertEquals(response.getStatus(), 401, "Unexpected response code.");
assertNotNull(entity, "Unexpected result: " + entity);
try {
JSONObject jsonObj = new JSONObject(entity);
assertTrue(jsonObj.has("error"), "The error type is null");
assertTrue(jsonObj.has("error_description"), "The error description is null");
} catch (JSONException e) {
e.printStackTrace();
fail(e.getMessage() + "\nResponse was: " + entity);
}
}
use of javax.ws.rs.core.MultivaluedHashMap in project oxAuth by GluuFederation.
the class AuthorizationCodeFlowEmbeddedTest method completeFlowStep3.
public void completeFlowStep3(final String tokenPath, final String refreshToken) throws Exception {
Builder request = ResteasyClientBuilder.newClient().target(url.toString() + tokenPath).request();
TokenRequest tokenRequest = new TokenRequest(GrantType.REFRESH_TOKEN);
tokenRequest.setRefreshToken(refreshToken);
tokenRequest.setScope("email read_stream manage_pages");
tokenRequest.setAuthUsername(clientId);
tokenRequest.setAuthPassword(clientSecret);
request.header("Authorization", "Basic " + tokenRequest.getEncodedCredentials());
Response response = request.post(Entity.form(new MultivaluedHashMap<String, String>(tokenRequest.getParameters())));
String entity = response.readEntity(String.class);
showResponse("completeFlowStep3", response, entity);
assertEquals(response.getStatus(), 200, "Unexpected response code.");
assertTrue(response.getHeaderString("Cache-Control") != null && response.getHeaderString("Cache-Control").equals("no-store"), "Unexpected result: " + response.getHeaderString("Cache-Control"));
assertTrue(response.getHeaderString("Pragma") != null && response.getHeaderString("Pragma").equals("no-cache"), "Unexpected result: " + response.getHeaderString("Pragma"));
assertNotNull(entity, "Unexpected result: " + entity);
try {
JSONObject jsonObj = new JSONObject(entity);
assertTrue(jsonObj.has("access_token"), "Unexpected result: access_token not found");
assertTrue(jsonObj.has("token_type"), "Unexpected result: token_type not found");
assertTrue(jsonObj.has("scope"), "Unexpected result: scope not found");
} catch (JSONException e) {
e.printStackTrace();
fail(e.getMessage() + "\nResponse was: " + entity);
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
}
use of javax.ws.rs.core.MultivaluedHashMap in project oxAuth by GluuFederation.
the class AuthorizationCodeFlowEmbeddedTest method revokeTokensStep2n3.
@Parameters({ "tokenPath", "redirectUri" })
@Test(dependsOnMethods = { "dynamicClientRegistration", "revokeTokensStep1" })
public void revokeTokensStep2n3(final String tokenPath, final String redirectUri) throws Exception {
Builder request = ResteasyClientBuilder.newClient().target(url.toString() + tokenPath).request();
TokenRequest tokenRequest = new TokenRequest(GrantType.AUTHORIZATION_CODE);
tokenRequest.setCode(authorizationCode2);
tokenRequest.setRedirectUri(redirectUri);
tokenRequest.setAuthUsername(clientId);
tokenRequest.setAuthPassword(clientSecret);
request.header("Authorization", "Basic " + tokenRequest.getEncodedCredentials());
Response response = request.post(Entity.form(new MultivaluedHashMap<String, String>(tokenRequest.getParameters())));
String entity = response.readEntity(String.class);
showResponse("revokeTokensStep2n3", response, entity);
assertEquals(response.getStatus(), 200, "Unexpected response code.");
assertTrue(response.getHeaderString("Cache-Control") != null && response.getHeaderString("Cache-Control").equals("no-store"), "Unexpected result: " + response.getHeaderString("Cache-Control"));
assertTrue(response.getHeaderString("Pragma") != null && response.getHeaderString("Pragma").equals("no-cache"), "Unexpected result: " + response.getHeaderString("Pragma"));
assertNotNull(entity, "Unexpected result: " + entity);
try {
JSONObject jsonObj = new JSONObject(entity);
assertTrue(jsonObj.has("access_token"), "Unexpected result: access_token not found");
assertTrue(jsonObj.has("token_type"), "Unexpected result: token_type not found");
assertTrue(jsonObj.has("refresh_token"), "Unexpected result: refresh_token not found");
assertTrue(jsonObj.has("id_token"), "Unexpected result: id_token not found");
accessToken1 = jsonObj.getString("access_token");
refreshToken1 = jsonObj.getString("refresh_token");
Builder request2 = ResteasyClientBuilder.newClient().target(url.toString() + tokenPath).request();
TokenRequest tokenRequest2 = new TokenRequest(GrantType.AUTHORIZATION_CODE);
tokenRequest2.setCode(authorizationCode2);
tokenRequest2.setRedirectUri(redirectUri);
tokenRequest2.setAuthUsername(clientId);
tokenRequest2.setAuthPassword(clientSecret);
request2.header("Authorization", "Basic " + tokenRequest2.getEncodedCredentials());
Response response2 = request2.post(Entity.form(new MultivaluedHashMap<String, String>(tokenRequest2.getParameters())));
String entity2 = response2.readEntity(String.class);
showResponse("revokeTokens step 3", response2, entity2);
assertEquals(response2.getStatus(), 400, "Unexpected response code.");
assertNotNull(entity2, "Unexpected result: " + entity2);
try {
JSONObject jsonObj2 = new JSONObject(entity2);
assertTrue(jsonObj2.has("error"), "The error type is null");
assertTrue(jsonObj2.has("error_description"), "The error description is null");
} catch (JSONException e) {
e.printStackTrace();
fail(e.getMessage() + "\nResponse was: " + entity2);
}
} catch (JSONException e) {
e.printStackTrace();
fail(e.getMessage() + "\nResponse was: " + entity);
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
}
use of javax.ws.rs.core.MultivaluedHashMap in project oxAuth by GluuFederation.
the class AuthorizationCodeFlowEmbeddedTest method completeFlowStep2.
@Parameters({ "tokenPath", "validateTokenPath", "redirectUri" })
@Test(dependsOnMethods = { "dynamicClientRegistration", "completeFlowStep1" })
public void completeFlowStep2(final String tokenPath, final String validateTokenPath, final String redirectUri) throws Exception {
Builder request = ResteasyClientBuilder.newClient().target(url.toString() + tokenPath).request();
TokenRequest tokenRequest = new TokenRequest(GrantType.AUTHORIZATION_CODE);
tokenRequest.setCode(authorizationCode1);
tokenRequest.setRedirectUri(redirectUri);
tokenRequest.setAuthUsername(clientId);
tokenRequest.setAuthPassword(clientSecret);
request.header("Authorization", "Basic " + tokenRequest.getEncodedCredentials());
Response response = request.post(Entity.form(new MultivaluedHashMap<String, String>(tokenRequest.getParameters())));
String entity = response.readEntity(String.class);
showResponse("completeFlowStep2", response, entity);
assertEquals(response.getStatus(), 200, "Unexpected response code.");
assertTrue(response.getHeaderString("Cache-Control") != null && response.getHeaderString("Cache-Control").equals("no-store"), "Unexpected result: " + response.getHeaderString("Cache-Control"));
assertTrue(response.getHeaderString("Pragma") != null && response.getHeaderString("Pragma").equals("no-cache"), "Unexpected result: " + response.getHeaderString("Pragma"));
assertNotNull(entity, "Unexpected result: " + entity);
try {
JSONObject jsonObj = new JSONObject(entity);
assertTrue(jsonObj.has("access_token"), "Unexpected result: access_token not found");
assertTrue(jsonObj.has("token_type"), "Unexpected result: token_type not found");
assertTrue(jsonObj.has("refresh_token"), "Unexpected result: refresh_token not found");
assertTrue(jsonObj.has("id_token"), "Unexpected result: id_token not found");
String accessToken = jsonObj.getString("access_token");
String refreshToken = jsonObj.getString("refresh_token");
completeFlowStep3(tokenPath, refreshToken);
} catch (JSONException e) {
e.printStackTrace();
fail(e.getMessage() + "\nResponse was: " + entity);
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
}
use of javax.ws.rs.core.MultivaluedHashMap in project oxAuth by GluuFederation.
the class ClientInfoRestWebServiceEmbeddedTest method requestClientInfoStep2PostImplicitFlow.
@Parameters({ "clientInfoPath" })
@Test(dependsOnMethods = "requestClientInfoStep1ImplicitFlow")
public void requestClientInfoStep2PostImplicitFlow(final String clientInfoPath) throws Exception {
Builder request = ResteasyClientBuilder.newClient().target(url.toString() + clientInfoPath).request();
request.header("Authorization", "Bearer " + accessToken1);
request.header("Content-Type", MediaType.APPLICATION_FORM_URLENCODED);
ClientInfoRequest clientInfoRequest = new ClientInfoRequest(null);
Response response = request.post(Entity.form(new MultivaluedHashMap<String, String>(clientInfoRequest.getParameters())));
String entity = response.readEntity(String.class);
showResponse("requestClientInfo step 2 POST Implicit Flow", response, entity);
assertEquals(response.getStatus(), 200, "Unexpected response code.");
assertTrue(response.getHeaderString("Cache-Control") != null && response.getHeaderString("Cache-Control").equals("no-store, private"), "Unexpected result: " + response.getHeaderString("Cache-Control"));
assertTrue(response.getHeaderString("Pragma") != null && response.getHeaderString("Pragma").equals("no-cache"), "Unexpected result: " + response.getHeaderString("Pragma"));
assertNotNull(entity, "Unexpected result: " + entity);
try {
JSONObject jsonObj = new JSONObject(entity);
assertTrue(jsonObj.has("displayName"), "Unexpected result: displayName not found");
assertTrue(jsonObj.has("inum"), "Unexpected result: inum not found");
assertTrue(jsonObj.has("oxAuthAppType"), "Unexpected result: oxAuthAppType not found");
assertTrue(jsonObj.has("oxAuthIdTokenSignedResponseAlg"), "Unexpected result: oxAuthIdTokenSignedResponseAlg not found");
assertTrue(jsonObj.has("oxAuthRedirectURI"), "Unexpected result: oxAuthRedirectURI not found");
assertTrue(jsonObj.has("oxAuthScope"), "Unexpected result: oxAuthScope not found");
} catch (JSONException e) {
e.printStackTrace();
fail(e.getMessage() + "\nResponse was: " + entity);
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
}
Aggregations