Search in sources :

Example 91 with AuthorizationRequest

use of org.xdi.oxauth.client.AuthorizationRequest in project oxAuth by GluuFederation.

the class ResponseTypesRestrictionEmbeddedTest method responseTypesCodeIdTokenStep4.

/**
	 * Authorization request with the other Response types combination should
	 * fail.
	 */
@Test(dependsOnMethods = "omittedResponseTypesStep3b", dataProvider = "responseTypesCodeIdTokenStep4DataProvider")
public void responseTypesCodeIdTokenStep4(final String authorizePath, final String userId, final String userSecret, final String redirectUri, final List<ResponseType> responseTypes) throws Exception {
    List<String> scopes = Arrays.asList("openid", "profile", "address", "email");
    String nonce = UUID.randomUUID().toString();
    AuthorizationRequest authorizationRequest = new AuthorizationRequest(responseTypes, clientId1, scopes, redirectUri, nonce);
    authorizationRequest.setState("af0ifjsldkj");
    authorizationRequest.getPrompts().add(Prompt.NONE);
    authorizationRequest.setAuthUsername(userId);
    authorizationRequest.setAuthPassword(userSecret);
    Builder request = ResteasyClientBuilder.newClient().target(url.toString() + authorizePath + "?" + authorizationRequest.getQueryString()).request();
    request.header("Authorization", "Basic " + authorizationRequest.getEncodedCredentials());
    request.header("Accept", MediaType.TEXT_PLAIN);
    Response response = request.get();
    String entity = response.readEntity(String.class);
    showResponse("responseTypesCodeIdTokenStep4", response, entity);
    if (response.getStatus() == 400) {
        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);
        }
    } else {
        fail("Unexpected response code: " + response.getStatus());
    }
}
Also used : Response(javax.ws.rs.core.Response) AuthorizationRequest(org.xdi.oxauth.client.AuthorizationRequest) JSONObject(org.codehaus.jettison.json.JSONObject) ResteasyClientBuilder(org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder) Builder(javax.ws.rs.client.Invocation.Builder) JSONException(org.codehaus.jettison.json.JSONException) Test(org.testng.annotations.Test) BaseTest(org.xdi.oxauth.BaseTest)

Example 92 with AuthorizationRequest

use of org.xdi.oxauth.client.AuthorizationRequest in project oxAuth by GluuFederation.

the class ResponseTypesRestrictionEmbeddedTest method responseTypesTokenIdTokenStep4.

/**
	 * Authorization request with the other Response types combination should
	 * fail.
	 */
@Test(dependsOnMethods = "responseTypesTokenIdTokenStep3", dataProvider = "responseTypesTokenIdTokenStep4DataProvider")
public void responseTypesTokenIdTokenStep4(final String authorizePath, final String userId, final String userSecret, final String redirectUri, final List<ResponseType> responseTypes) throws Exception {
    List<String> scopes = Arrays.asList("openid", "profile", "address", "email");
    String nonce = UUID.randomUUID().toString();
    AuthorizationRequest authorizationRequest = new AuthorizationRequest(responseTypes, clientId3, scopes, redirectUri, nonce);
    authorizationRequest.setState("af0ifjsldkj");
    authorizationRequest.getPrompts().add(Prompt.NONE);
    authorizationRequest.setAuthUsername(userId);
    authorizationRequest.setAuthPassword(userSecret);
    Builder request = ResteasyClientBuilder.newClient().target(url.toString() + authorizePath + "?" + authorizationRequest.getQueryString()).request();
    request.header("Authorization", "Basic " + authorizationRequest.getEncodedCredentials());
    request.header("Accept", MediaType.TEXT_PLAIN);
    Response response = request.get();
    String entity = response.readEntity(String.class);
    showResponse("responseTypesTokenIdTokenStep4", response, entity);
    if (response.getStatus() == 400) {
        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);
        }
    } else {
        fail("Unexpected response code: " + response.getStatus());
    }
}
Also used : Response(javax.ws.rs.core.Response) AuthorizationRequest(org.xdi.oxauth.client.AuthorizationRequest) JSONObject(org.codehaus.jettison.json.JSONObject) ResteasyClientBuilder(org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder) Builder(javax.ws.rs.client.Invocation.Builder) JSONException(org.codehaus.jettison.json.JSONException) Test(org.testng.annotations.Test) BaseTest(org.xdi.oxauth.BaseTest)

Example 93 with AuthorizationRequest

use of org.xdi.oxauth.client.AuthorizationRequest in project oxTrust by GluuFederation.

the class OpenIdClient method getRedirectionUrl.

/**
	 * {@InheritDoc}
	 */
public String getRedirectionUrl(final WebContext context) {
    init();
    final String state = RandomStringUtils.randomAlphanumeric(10);
    final String nonce = RandomStringUtils.randomAlphanumeric(10);
    final AuthorizationRequest authorizationRequest = new AuthorizationRequest(Arrays.asList(ResponseType.CODE), this.clientId, this.appConfiguration.getOpenIdScopes(), this.appConfiguration.getOpenIdRedirectUrl(), null);
    authorizationRequest.setState(state);
    authorizationRequest.setNonce(nonce);
    context.setSessionAttribute(getName() + STATE_PARAMETER, state);
    final String redirectionUrl = this.openIdConfiguration.getAuthorizationEndpoint() + "?" + authorizationRequest.getQueryString();
    logger.debug("oxAuth redirection Url: '{}'", redirectionUrl);
    return redirectionUrl;
}
Also used : AuthorizationRequest(org.xdi.oxauth.client.AuthorizationRequest)

Aggregations

AuthorizationRequest (org.xdi.oxauth.client.AuthorizationRequest)93 Test (org.testng.annotations.Test)89 BaseTest (org.xdi.oxauth.BaseTest)89 Builder (javax.ws.rs.client.Invocation.Builder)88 Response (javax.ws.rs.core.Response)88 ResteasyClientBuilder (org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder)88 Parameters (org.testng.annotations.Parameters)86 ResponseType (org.xdi.oxauth.model.common.ResponseType)85 URI (java.net.URI)79 URISyntaxException (java.net.URISyntaxException)79 REGISTRATION_CLIENT_URI (org.xdi.oxauth.model.register.RegisterResponseParam.REGISTRATION_CLIENT_URI)73 JSONException (org.codehaus.jettison.json.JSONException)62 RegisterResponse (org.xdi.oxauth.client.RegisterResponse)50 JwtAuthorizationRequest (org.xdi.oxauth.client.model.authorize.JwtAuthorizationRequest)46 OxAuthCryptoProvider (org.xdi.oxauth.model.crypto.OxAuthCryptoProvider)41 Claim (org.xdi.oxauth.client.model.authorize.Claim)40 ArrayList (java.util.ArrayList)11 JSONObject (org.codehaus.jettison.json.JSONObject)10 InvalidJwtException (org.xdi.oxauth.model.exception.InvalidJwtException)4 BufferedWriter (java.io.BufferedWriter)2