Search in sources :

Example 6 with TokenResponse

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;
}
Also used : TokenResponse(org.xdi.oxauth.client.TokenResponse) TokenClient(org.xdi.oxauth.client.TokenClient)

Example 7 with TokenResponse

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");
}
Also used : TokenResponse(org.xdi.oxauth.client.TokenResponse) TokenClient(org.xdi.oxauth.client.TokenClient) Parameters(org.testng.annotations.Parameters)

Example 8 with TokenResponse

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;
}
Also used : TokenResponse(org.xdi.oxauth.client.TokenResponse) Token(org.xdi.oxauth.model.uma.wrapper.Token) TokenClient(org.xdi.oxauth.client.TokenClient)

Aggregations

TokenClient (org.xdi.oxauth.client.TokenClient)8 TokenResponse (org.xdi.oxauth.client.TokenResponse)8 Parameters (org.testng.annotations.Parameters)3 TokenRequest (org.xdi.oxauth.client.TokenRequest)2 Token (org.xdi.oxauth.model.uma.wrapper.Token)2 ArrayList (java.util.ArrayList)1 Test (org.testng.annotations.Test)1 BaseTest (org.xdi.oxauth.BaseTest)1 AuthorizationRequest (org.xdi.oxauth.client.AuthorizationRequest)1 AuthorizationResponse (org.xdi.oxauth.client.AuthorizationResponse)1 AuthorizeClient (org.xdi.oxauth.client.AuthorizeClient)1 RegisterClient (org.xdi.oxauth.client.RegisterClient)1 RegisterRequest (org.xdi.oxauth.client.RegisterRequest)1 RegisterResponse (org.xdi.oxauth.client.RegisterResponse)1 ResponseType (org.xdi.oxauth.model.common.ResponseType)1