public static Token request(final String tokenUrl, final TokenRequest tokenRequest) throws Exception { if (tokenRequest.getGrantType() != GrantType.CLIENT_CREDENTIALS) { return null; } TokenClient tokenClient = new TokenClient(tokenUrl); tokenClient.setRequest(tokenRequest); TokenResponse response = tokenClient.exec(); if (response.getStatus() == 200) { final String patToken = response.getAccessToken(); final Integer expiresIn = response.getExpiresIn(); if (Util.allNotBlank(patToken)) { return new Token(null, null, patToken, response.getScope(), expiresIn); } } return null; }
final TokenClient tokenClient = new TokenClient(this.openIdConfiguration.getTokenEndpoint()); final TokenResponse tokenResponse = tokenClient.execAuthorizationCode(credential.getAuthorizationCode(), this.appConfiguration.getOpenIdRedirectUrl(), this.clientId, this.clientSecret); logger.trace("tokenResponse.getStatus(): '{}'", tokenResponse.getStatus()); logger.trace("tokenResponse.getErrorType(): '{}'", tokenResponse.getErrorType());
public static Token request(final String tokenUrl, final String umaClientId, final String umaClientSecret, UmaScopeType scopeType, ClientExecutor clientExecutor, String... scopeArray) throws Exception { String scope = scopeType.getValue(); if (scopeArray != null && scopeArray.length > 0) { for (String s : scopeArray) { scope = scope + " " + s; } } TokenClient tokenClient = new TokenClient(tokenUrl); if (clientExecutor != null) { tokenClient.setExecutor(clientExecutor); } TokenResponse response = tokenClient.execClientCredentialsGrant(scope, umaClientId, umaClientSecret); if (response.getStatus() == 200) { final String patToken = response.getAccessToken(); final Integer expiresIn = response.getExpiresIn(); if (Util.allNotBlank(patToken)) { return new Token(null, null, patToken, scopeType.getValue(), expiresIn); } } return null; }
/** * <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(); }
tokenRequest.setAuthenticationMethod(AuthenticationMethod.TLS_CLIENT_AUTH); TokenClient tokenClient = new TokenClient("https://ce-ob.gluu.org/oxauth/restv1/token"); tokenClient.setExecutor(new ApacheHttpClient4Executor(httpclient)); tokenClient.setRequest(tokenRequest); TokenResponse tokenResponse = tokenClient.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); } }
private void requestAccessTokenPassword(final String userId, final String userSecret, String clientId, String clientSecret) throws Exception { // Request Resource Owner Credentials Grant String scope = "openid"; TokenClient tokenClient = new TokenClient(tokenEndpoint); TokenResponse response1 = tokenClient.execResourceOwnerPasswordCredentialsGrant(userId, userSecret, scope, clientId, clientSecret); assertEquals(response1.getStatus(), 200, "Unexpected response code: " + response1.getStatus()); assertNotNull(response1.getEntity(), "The entity is null"); assertNotNull(response1.getAccessToken(), "The access token is null"); assertNotNull(response1.getTokenType(), "The token type is null"); assertNotNull(response1.getRefreshToken(), "The refresh token is null"); assertNotNull(response1.getScope(), "The scope is null"); assertNotNull(response1.getIdToken(), "The id token is null"); }
String refreshToken; TokenClient tokenClient = new TokenClient(tokenEndpoint); TokenResponse tokenResponse = tokenClient.execAuthorizationCode(authorizationCode, redirectUri, clientId, clientSecret); TokenClient tokenClient = new TokenClient(tokenEndpoint); TokenResponse tokenResponse = tokenClient.execAuthorizationCode(authorizationCode, redirectUri, clientId, clientSecret); TokenClient tokenClient = new TokenClient(tokenEndpoint); TokenResponse tokenResponse = tokenClient.execRefreshToken(scope, refreshToken, clientId, clientSecret);
/** * Test for the obtaining UMA PAT token using refresh token */ //@Test(dependsOnMethods = {"testObtainPatTokenFlow"}) @Parameters({"umaPatClientId", "umaPatClientSecret"}) public void testObtainPatTokenUsingRefreshTokenFlow(final String umaPatClientId, final String umaPatClientSecret) throws Exception { showTitle("testObtainPatTokenUsingRefreshTokenFlow"); // Request new access token using the refresh token. TokenClient tokenClient1 = new TokenClient(tokenEndpoint); TokenResponse response1 = tokenClient1.execRefreshToken(m_pat.getScope(), m_pat.getRefreshToken(), umaPatClientId, umaPatClientSecret); showClient(tokenClient1); assertEquals(response1.getStatus(), 200, "Unexpected response code: " + response1.getStatus()); assertNotNull(response1.getEntity(), "The entity is null"); assertNotNull(response1.getAccessToken(), "The access token is null"); assertNotNull(response1.getTokenType(), "The token type is null"); assertNotNull(response1.getRefreshToken(), "The refresh token is null"); assertNotNull(response1.getScope(), "The scope is null"); } }
TokenClient tokenClient = new TokenClient(tokenEndpoint); TokenResponse response = tokenClient.execClientCredentialsGrant(scope, clientId, clientSecret);
tokenRequest.setAuthPassword(clientSecret); TokenClient tokenClient = new TokenClient(tokenEndpoint); tokenClient.setExecutor(clientExecutor(true)); tokenClient.setRequest(tokenRequest); TokenResponse tokenResponse = tokenClient.exec();
String scope = "openid profile address email"; TokenClient tokenClient = new TokenClient(tokenEndpoint); TokenResponse response1 = tokenClient.execResourceOwnerPasswordCredentialsGrant(username, password, scope, clientId, clientSecret);
/** * <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(); }
TokenClient tokenClient1 = new TokenClient(tokenEndpoint); TokenResponse response2 = tokenClient1.execAuthorizationCode(authorizationCode, redirectUri, clientId, clientSecret); TokenClient tokenClient2 = new TokenClient(tokenEndpoint); TokenResponse response4 = tokenClient2.execAuthorizationCode(authorizationCode, redirectUri, clientId, clientSecret); TokenClient tokenClient3 = new TokenClient(tokenEndpoint); TokenResponse response5 = tokenClient3.execRefreshToken(scope, refreshToken, clientId, clientSecret);
String refreshToken = "tGzv3JOkF0XG5Qx2TlKWIA"; TokenClient tokenClient = new TokenClient(tokenEndpoint); TokenResponse response = tokenClient.execRefreshToken(scope, refreshToken, clientId, clientSecret);
tokenRequest.setScope(scope); TokenClient tokenClient1 = new TokenClient(tokenUrl); tokenClient1.setRequest(tokenRequest); TokenResponse response2 = tokenClient1.exec();
TokenClient tokenClient1 = new TokenClient(oAuthTokenUrl); TokenResponse tokenResponse = tokenClient1.execAuthorizationCode(authorizationCode, redirectURL, oAuthClientId, oAuthClientPassword); if (tokenResponse == null) { log.error("Get empty token response. User can't log into application");
String scope = "openid profile address email org_name work_phone"; TokenClient tokenClient = new TokenClient(tokenEndpoint); TokenResponse response1 = tokenClient.execResourceOwnerPasswordCredentialsGrant(username, password, scope, clientId, clientSecret);
/** * <p> * Executes the call to the REST Service requesting the authorization and * processes the response. * </p> * <p> * The client uses an extension grant type by specifying the grant type * using an absolute URI (defined by the authorization server) as the value * of the grant_type parameter of the token endpoint, and by adding any * additional parameters necessary. * </p> * * @param grantTypeUri Absolute URI. * @param assertion Assertion grant type. * @param clientId The client identifier. * @param clientSecret The client secret. * @return The token response. */ public TokenResponse execExtensionGrant(String grantTypeUri, String assertion, String clientId, String clientSecret) { GrantType grantType = GrantType.fromString(grantTypeUri); setRequest(new TokenRequest(grantType)); getRequest().setAssertion(assertion); getRequest().setAuthUsername(clientId); getRequest().setAuthPassword(clientSecret); return exec(); }
@Parameters({"userId", "userSecret"}) @Test(dependsOnMethods = "requestClientRegistrationWithCustomAttributes") public void requestAccessTokenCustomClientAuth2(final String userId, final String userSecret) throws Exception { showTitle("requestAccessTokenCustomClientAuth2"); String username = userId; String password = userSecret; TokenRequest tokenRequest = new TokenRequest(GrantType.RESOURCE_OWNER_PASSWORD_CREDENTIALS); tokenRequest.setUsername(username); tokenRequest.setPassword(password); tokenRequest.setAuthenticationMethod(AuthenticationMethod.CLIENT_SECRET_POST); tokenRequest.addCustomParameter("myCustomAttr1", customAttrValue1); TokenClient tokenClient = new TokenClient(tokenEndpoint); tokenClient.setRequest(tokenRequest); TokenResponse tokenResponse = tokenClient.exec(); showClient(tokenClient); assertEquals(tokenResponse.getStatus(), 200, "Unexpected response code: " + tokenResponse.getStatus()); assertNotNull(tokenResponse.getEntity(), "The entity is null"); assertNotNull(tokenResponse.getAccessToken(), "The access token is null"); assertNotNull(tokenResponse.getTokenType(), "The token type is null"); assertNotNull(tokenResponse.getRefreshToken(), "The refresh token is null"); } }