use of org.xdi.oxauth.client.TokenResponse in project oxTrust by GluuFederation.
the class OpenIdClient method getAccessToken.
private String getAccessToken(final OpenIdCredentials credential) {
// Request access token using the authorization code
logger.debug("Getting access token");
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());
final String accessToken = tokenResponse.getAccessToken();
logger.trace("accessToken : " + accessToken);
return accessToken;
}
use of org.xdi.oxauth.client.TokenResponse in project oxAuth by GluuFederation.
the class ObtainPatTokenFlowHttpTest method testObtainPatTokenUsingRefreshTokenFlow.
/**
* 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");
}
use of org.xdi.oxauth.client.TokenResponse in project oxAuth by GluuFederation.
the class UmaClient method request.
public static Token request(final String tokenUrl, final String umaClientId, final String umaClientSecret, UmaScopeType scopeType, 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);
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;
}
Aggregations