public TokenRequest build() { final TokenRequest request = new TokenRequest(grantType); request.setScope(scope); return request; } }
@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); } }
public static Token requestWithClientSecretJwt(final String tokenUrl, final String umaClientId, final String umaClientSecret, AuthenticationMethod authenticationMethod, SignatureAlgorithm signatureAlgorithm, String audience, UmaScopeType scopeType, String... scopeArray) throws Exception { String scope = scopeType.getValue(); if (scopeArray != null && scopeArray.length > 0) { for (String s : scopeArray) { scope = scope + " " + s; } } TokenRequest request = new TokenRequest(GrantType.CLIENT_CREDENTIALS); request.setAuthUsername(umaClientId); request.setAuthPassword(umaClientSecret); request.setScope(scope); request.setAuthenticationMethod(authenticationMethod); request.setAlgorithm(signatureAlgorithm); request.setAudience(audience); return request(tokenUrl, request); }
tokenRequest.setScope("email read_stream manage_pages"); tokenRequest.setAuthUsername(clientId); tokenRequest.setAuthPassword(clientSecret);
tokenRequest.setScope("email read_stream manage_pages"); tokenRequest.setAuthUsername(clientId); tokenRequest.setAuthPassword(clientSecret);
tokenRequest.setScope("email read_stream manage_pages"); tokenRequest.setAuthUsername(clientId); tokenRequest.setAuthPassword(clientSecret);
tokenRequest.setUsername(userId); tokenRequest.setPassword(userSecret); tokenRequest.setScope("profile email"); tokenRequest.setAuthenticationMethod(AuthenticationMethod.CLIENT_SECRET_POST); tokenRequest.addCustomParameter("myCustomAttr1", customAttrValue1);
@Parameters({"tokenPath", "userId", "userSecret", "audience"}) @Test public void requestAccessTokenWithClientSecretJwtFail(final String tokenPath, final String userId, final String userSecret, final String audience) throws Exception { Builder request = ResteasyClientBuilder.newClient().target(url.toString() + tokenPath).request(); request.header("Content-Type", MediaType.APPLICATION_FORM_URLENCODED); TokenRequest tokenRequest = new TokenRequest(GrantType.RESOURCE_OWNER_PASSWORD_CREDENTIALS); tokenRequest.setUsername(userId); tokenRequest.setPassword(userSecret); tokenRequest.setScope("email read_stream manage_pages"); tokenRequest.setAuthPassword("INVALID_SECRET"); tokenRequest.setAuthenticationMethod(AuthenticationMethod.CLIENT_SECRET_JWT); tokenRequest.setAudience(audience); Response response = request .post(Entity.form(new MultivaluedHashMap<String, String>(tokenRequest.getParameters()))); String entity = response.readEntity(String.class); showResponse("requestAccessTokenWithClientSecretJwt Fail", 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); } }
/** * <p> * Executes the call to the REST Service requesting the authorization and * processes the response. * </p> * <p> * The client can request an access token using only its client credentials * when the client is requesting access to the protected resources under its * control, or those of another resource owner which has been previously * arranged with the authorization server. The client credentials grant type * must only be used by confidential clients. * </p> * * @param scope The scope of the access request. This parameter is optional. * @param clientId The client identifier. * @param clientSecret The client secret. * @return The token response. */ public TokenResponse execClientCredentialsGrant( String scope, String clientId, String clientSecret) { setRequest(new TokenRequest(GrantType.CLIENT_CREDENTIALS)); getRequest().setScope(scope); getRequest().setAuthUsername(clientId); getRequest().setAuthPassword(clientSecret); return exec(); }
tokenRequest.setUsername(userId); tokenRequest.setPassword(userSecret); tokenRequest.setScope("email read_stream manage_pages"); tokenRequest.setAuthUsername(clientId2); tokenRequest.setAuthPassword(clientSecret2);
tokenRequest.setUsername(userId); tokenRequest.setPassword(userSecret); tokenRequest.setScope("email read_stream manage_pages"); tokenRequest.setAuthUsername(clientId5); tokenRequest.setAuthPassword(clientSecret5);
tokenRequest.setUsername(userId); tokenRequest.setPassword(userSecret); tokenRequest.setScope("email read_stream manage_pages"); tokenRequest.setAuthUsername(clientId4); tokenRequest.setAuthPassword(clientSecret4);
tokenRequest.setUsername(userId); tokenRequest.setPassword(userSecret); tokenRequest.setScope("email read_stream manage_pages"); tokenRequest.setAuthUsername(clientId5); tokenRequest.setAuthPassword(clientSecret5);
tokenRequest.setScope("email read_stream manage_pages"); tokenRequest.setAuthUsername(clientId); tokenRequest.setAuthPassword(clientSecret);
tokenRequest.setUsername(userId); tokenRequest.setPassword(userSecret); tokenRequest.setScope("email read_stream manage_pages"); tokenRequest.setAuthUsername(clientId3); tokenRequest.setAuthPassword(clientSecret3);
tokenRequest.setUsername(userId); tokenRequest.setPassword(userSecret); tokenRequest.setScope("email read_stream manage_pages"); tokenRequest.setAuthUsername(clientId2); tokenRequest.setAuthPassword(clientSecret2);
tokenRequest.setUsername(userId); tokenRequest.setPassword(userSecret); tokenRequest.setScope("email read_stream manage_pages"); tokenRequest.setAuthUsername(clientId4); tokenRequest.setAuthPassword(clientSecret4);
tokenRequest.setUsername(userId); tokenRequest.setPassword(userSecret); tokenRequest.setScope("email read_stream manage_pages"); tokenRequest.setAuthUsername(clientId3); tokenRequest.setAuthPassword(clientSecret3);
/** * <p> * Executes the call to the REST Service requesting the authorization and * processes the response. * </p> * <p> * If the authorization server issued a refresh token to the client, the * client can make a request to the token endpoint for a new access token. * </p> * * @param scope The scope of the access request. This value is optional. * @param refreshToken The refresh token issued to the client. This value is * required. * @param clientId The client identifier. * @param clientSecret The client secret. * @return The token response. */ public TokenResponse execRefreshToken(String scope, String refreshToken, String clientId, String clientSecret) { setRequest(new TokenRequest(GrantType.REFRESH_TOKEN)); getRequest().setScope(scope); getRequest().setRefreshToken(refreshToken); getRequest().setAuthUsername(clientId); getRequest().setAuthPassword(clientSecret); return exec(); }
public void exec() { try { TokenRequest request = new TokenRequest(grantType); request.setAuthUsername(clientId); request.setAuthPassword(clientSecret); request.setCode(code); request.setRedirectUri(redirectUri); request.setUsername(username); request.setPassword(password); request.setScope(scope); request.setAssertion(assertion); request.setRefreshToken(refreshToken); request.setAuthenticationMethod(authenticationMethod); if (authenticationMethod.equals(AuthenticationMethod.CLIENT_SECRET_JWT)) { request.setAudience(tokenEndpoint); } TokenClient client = new TokenClient(tokenEndpoint); client.setRequest(request); TokenResponse response = client.exec(); if (response.getStatus() == 200) { userInfoAction.setAccessToken(response.getAccessToken()); } showResults = true; requestString = client.getRequestAsString(); responseString = client.getResponseAsString(); } catch (Exception e) { log.error(e.getMessage(), e); } }