@Test public void testEncode2() { showTitle("testEncode2"); String clientId = "a+b"; String clientSecret = "c+d"; TokenRequest tokenRequest = new TokenRequest(GrantType.AUTHORIZATION_CODE); tokenRequest.setAuthUsername(clientId); tokenRequest.setAuthPassword(clientSecret); tokenRequest.setAuthenticationMethod(AuthenticationMethod.CLIENT_SECRET_BASIC); assertEquals(tokenRequest.getEncodedCredentials(), "YSUyQmI6YyUyQmQ="); }
@Test public void testEncode3() { showTitle("testEncode3"); String clientId = "@!12AD!0008!6D30.23D7"; String clientSecret = "P@55W0rd!"; TokenRequest tokenRequest = new TokenRequest(GrantType.AUTHORIZATION_CODE); tokenRequest.setAuthUsername(clientId); tokenRequest.setAuthPassword(clientSecret); tokenRequest.setAuthenticationMethod(AuthenticationMethod.CLIENT_SECRET_BASIC); assertEquals(tokenRequest.getEncodedCredentials(), "JTQwJTIxMTJBRCUyMTAwMDglMjE2RDMwLjIzRDc6UCU0MDU1VzByZCUyMQ=="); }
@Test public void testEncode1() { showTitle("testEncode1"); String clientId = "Aladdin"; String clientSecret = "open sesame"; TokenRequest tokenRequest = new TokenRequest(GrantType.AUTHORIZATION_CODE); tokenRequest.setAuthUsername(clientId); tokenRequest.setAuthPassword(clientSecret); tokenRequest.setAuthenticationMethod(AuthenticationMethod.CLIENT_SECRET_BASIC); assertEquals(tokenRequest.getEncodedCredentials(), "QWxhZGRpbjpvcGVuK3Nlc2FtZQ=="); }
tokenRequest.setAuthPassword(clientSecret); request.header("Authorization", "Basic " + tokenRequest.getEncodedCredentials());
@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); } }
tokenRequest.setAuthPassword(clientSecret); request.header("Authorization", "Basic " + tokenRequest.getEncodedCredentials());
tokenRequest.setAuthPassword(clientSecret); request.header("Authorization", "Basic " + tokenRequest.getEncodedCredentials()); request.header("Content-Type", MediaType.APPLICATION_FORM_URLENCODED);
tokenRequest.setAuthPassword(clientSecret); request.header("Authorization", "Basic " + tokenRequest.getEncodedCredentials());
@Parameters({"tokenPath", "redirectUri"}) @Test(dependsOnMethods = "dynamicClientRegistration") public void requestAccessToken(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("6f6f3f01-a034-4336-bf31-2e74868e5838"); tokenRequest.setRedirectUri(redirectUri); tokenRequest.setAuthUsername(clientId); tokenRequest.setAuthPassword(clientSecret); request.header("Authorization", "Basic " + tokenRequest.getEncodedCredentials()); request.header("Content-Type", MediaType.APPLICATION_FORM_URLENCODED); Response response = request .post(Entity.form(new MultivaluedHashMap<String, String>(tokenRequest.getParameters()))); String entity = response.readEntity(String.class); showResponse("requestAccessToken", response, entity); assertEquals(response.getStatus(), 400, "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); } }
tokenRequest.setAuthPassword(clientSecret2); request.header("Authorization", "Basic " + tokenRequest.getEncodedCredentials()); request.header("Content-Type", MediaType.APPLICATION_FORM_URLENCODED);
tokenRequest.setAuthPassword(clientSecret2); request.header("Authorization", "Basic " + tokenRequest.getEncodedCredentials()); request.header("Content-Type", MediaType.APPLICATION_FORM_URLENCODED);
tokenRequest.setAuthPassword(clientSecret1); request.header("Authorization", "Basic " + tokenRequest.getEncodedCredentials()); request.header("Content-Type", MediaType.APPLICATION_FORM_URLENCODED);
tokenRequest.setAuthPassword(clientSecret); request.header("Authorization", "Basic " + tokenRequest.getEncodedCredentials()); request.header("Content-Type", MediaType.APPLICATION_FORM_URLENCODED);
tokenRequest.setAuthPassword(clientSecret); request.header("Authorization", "Basic " + tokenRequest.getEncodedCredentials()); request.header("Content-Type", MediaType.APPLICATION_FORM_URLENCODED);
tokenRequest.setAuthPassword(clientSecret4); request.header("Authorization", "Basic " + tokenRequest.getEncodedCredentials()); request.header("Content-Type", MediaType.APPLICATION_FORM_URLENCODED);
tokenRequest.addCustomParameter("inum", userInum); request.header("Authorization", "Basic " + tokenRequest.getEncodedCredentials()); request.header("Content-Type", MediaType.APPLICATION_FORM_URLENCODED); Response response = request
tokenRequest.setAuthPassword(clientSecret); request.header("Authorization", "Basic " + tokenRequest.getEncodedCredentials()); request.header("Content-Type", MediaType.APPLICATION_FORM_URLENCODED);
tokenRequest.setAuthPassword(clientSecret); request.header("Authorization", "Basic " + tokenRequest.getEncodedCredentials()); request.header("Content-Type", MediaType.APPLICATION_FORM_URLENCODED);
tokenRequest.setAuthPassword(clientSecret3); request.header("Authorization", "Basic " + tokenRequest.getEncodedCredentials()); request.header("Content-Type", MediaType.APPLICATION_FORM_URLENCODED);
tokenRequest.setAuthPassword(clientSecret5); request.header("Authorization", "Basic " + tokenRequest.getEncodedCredentials()); request.header("Content-Type", MediaType.APPLICATION_FORM_URLENCODED);