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"); }
logger.trace("tokenResponse.getStatus(): '{}'", tokenResponse.getStatus()); logger.trace("tokenResponse.getErrorType(): '{}'", tokenResponse.getErrorType()); final String accessToken = tokenResponse.getAccessToken(); logger.trace("accessToken : " + accessToken); final String idToken = tokenResponse.getIdToken(); logger.trace("idToken : " + idToken);
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; }
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; }
assertEquals(tokenResponse.getStatus(), 401, "Unexpected response code: " + tokenResponse.getStatus()); assertNotNull(tokenResponse.getErrorType()); assertEquals(tokenResponse.getErrorType(), TokenErrorResponseType.INVALID_CLIENT); assertNotNull(tokenResponse.getErrorDescription());
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"); accessToken = tokenResponse.getAccessToken(); refreshToken = tokenResponse.getRefreshToken(); assertEquals(tokenResponse.getStatus(), 400, "Unexpected response code: " + tokenResponse.getStatus()); assertNotNull(tokenResponse.getEntity(), "The entity is null"); assertNotNull(tokenResponse.getErrorType(), "The error type is null"); assertNotNull(tokenResponse.getErrorDescription(), "The error description is null");
assertEquals(response.getStatus(), 400, "Unexpected response code: " + response.getStatus()); assertNotNull(response.getEntity(), "The entity is null"); assertNotNull(response.getErrorType(), "The error type is null"); assertNotNull(response.getErrorDescription(), "The error description is null");
TokenResponse response2 = tokenClient1.exec(); if (response2.getStatus() == 200) { final String patToken = response2.getAccessToken(); final String patRefreshToken = response2.getRefreshToken(); final Integer expiresIn = response2.getExpiresIn(); if (Util.allNotBlank(patToken, patRefreshToken)) { return new Token(authorizationCode, patRefreshToken, patToken, scope, expiresIn);
log.trace("tokenResponse.getErrorType() : " + tokenResponse.getErrorType()); String accessToken = tokenResponse.getAccessToken(); String idToken = tokenResponse.getIdToken(); log.trace("accessToken : " + accessToken); log.trace("idToken : " + idToken); oAuthData.setAccessTokenExpirationInSeconds(tokenResponse.getExpiresIn()); oAuthData.setScopes(scopes); oAuthData.setIdToken(idToken);
ClientUtils.showClient(authorizeClient); assertTrue(response2.getStatus() == 200); final String patToken = response2.getAccessToken(); final String patRefreshToken = response2.getRefreshToken(); assertTrue(Util.allNotBlank(patToken, patRefreshToken));
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); } }
assertEquals(tokenResponse.getStatus(), 401, "Unexpected response code: " + tokenResponse.getStatus()); assertNotNull(tokenResponse.getErrorType()); assertEquals(tokenResponse.getErrorType(), TokenErrorResponseType.INVALID_CLIENT); assertNotNull(tokenResponse.getErrorDescription());
assertEquals(response.getStatus(), 401, "Unexpected response code: " + response.getStatus()); assertNotNull(response.getEntity(), "The entity is null"); assertNotNull(response.getErrorType(), "The error type is null"); assertNotNull(response.getErrorDescription(), "The error description is null");
/** * 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"); } }
assertEquals(tokenResponse.getStatus(), 401, "Unexpected response code: " + tokenResponse.getStatus()); assertNotNull(tokenResponse.getErrorType()); assertEquals(tokenResponse.getErrorType(), TokenErrorResponseType.INVALID_CLIENT); assertNotNull(tokenResponse.getErrorDescription());
assertEquals(tokenResponse.getStatus(), 401, "Unexpected response code: " + tokenResponse.getStatus()); assertNotNull(tokenResponse.getEntity(), "The entity is null"); assertNotNull(tokenResponse.getErrorType(), "The error type is null"); assertNotNull(tokenResponse.getErrorDescription(), "The error description is null");
@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"); } }
assertEquals(tokenResponse.getStatus(), 401, "Unexpected response code: " + tokenResponse.getStatus()); assertNotNull(tokenResponse.getErrorType()); assertEquals(tokenResponse.getErrorType(), TokenErrorResponseType.INVALID_CLIENT); assertNotNull(tokenResponse.getErrorDescription());
assertEquals(response.getStatus(), 401, "Unexpected response code: " + response.getStatus()); assertNotNull(response.getEntity(), "The entity is null"); assertNotNull(response.getErrorType(), "The error type is null"); assertNotNull(response.getErrorDescription(), "The error description is null");
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"); String accessToken = response1.getAccessToken();