Java Code Examples for org.gluu.oxauth.client.RegisterRequest#setClientName()

The following examples show how to use org.gluu.oxauth.client.RegisterRequest#setClientName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RegistrationRestWebServiceHttpTest.java    From oxAuth with MIT License 4 votes vote down vote up
@Parameters({"redirectUris", "sectorIdentifierUri"})
  @Test
  public void requestClientAssociate1(final String redirectUris, final String sectorIdentifierUri) throws Exception {
      showTitle("requestClientAssociate1");

      // 1. Register Client
      RegisterRequest registerRequest = new RegisterRequest(ApplicationType.WEB, "oxAuth test app",
              StringUtils.spaceSeparatedToList(redirectUris));
      registerRequest.setSectorIdentifierUri(sectorIdentifierUri);
      registerRequest.setGrantTypes(Arrays.asList(
              AUTHORIZATION_CODE,
              IMPLICIT,
              RESOURCE_OWNER_PASSWORD_CREDENTIALS,
              CLIENT_CREDENTIALS,
              REFRESH_TOKEN,
              OXAUTH_UMA_TICKET));
      registerRequest.setResponseTypes(Arrays.asList(
              CODE,
              TOKEN,
              ID_TOKEN
      ));

      RegisterClient registerClient = new RegisterClient(registrationEndpoint);
      registerClient.setRequest(registerRequest);
      RegisterResponse registerResponse = registerClient.exec();

      showClient(registerClient);
      assertEquals(registerResponse.getStatus(), 200, "Unexpected response code: " + registerResponse.getEntity());
      assertNotNull(registerResponse.getClientId());
      assertNotNull(registerResponse.getClientSecret());
      assertNotNull(registerResponse.getRegistrationAccessToken());
      assertNotNull(registerResponse.getClientSecretExpiresAt());

      String registrationAccessToken = registerResponse.getRegistrationAccessToken();
      String registrationClientUri = registerResponse.getRegistrationClientUri();

      // 2. Client Update
      String newClientName = "New Client Name";

      RegisterRequest clientUpdateRequest = new RegisterRequest(registrationAccessToken);
      clientUpdateRequest.setHttpMethod(HttpMethod.PUT);
      clientUpdateRequest.setClientName(newClientName);

      RegisterClient clientUpdateClient = new RegisterClient(registrationClientUri);
      clientUpdateClient.setRequest(clientUpdateRequest);
      RegisterResponse clientUpdateResponse = clientUpdateClient.exec();

      showClient(clientUpdateClient);
      assertEquals(clientUpdateResponse.getStatus(), 200, "Unexpected response code: " + clientUpdateResponse.getEntity());
      assertEquals(clientUpdateResponse.getClaims().get(CLIENT_NAME.toString()), newClientName);
      assertEquals(clientUpdateResponse.getClientId(), registerResponse.getClientId());
      assertEquals(clientUpdateResponse.getClientSecret(), registerResponse.getClientSecret());
      assertEquals(clientUpdateResponse.getRegistrationAccessToken(), registerResponse.getRegistrationAccessToken());
      assertEquals(clientUpdateResponse.getRegistrationClientUri(), registerResponse.getRegistrationClientUri());
      assertEquals(clientUpdateResponse.getClientIdIssuedAt(), registerResponse.getClientIdIssuedAt());
      assertEquals(clientUpdateResponse.getClientSecretExpiresAt(), registerResponse.getClientSecretExpiresAt());
      assertEquals(clientUpdateResponse.getResponseTypes(), registerResponse.getResponseTypes());
      assertEquals(clientUpdateResponse.getGrantTypes(), registerResponse.getGrantTypes());
      assertEquals(clientUpdateResponse.getClaims().get(REDIRECT_URIS.toString()), registerResponse.getClaims().get(REDIRECT_URIS.toString()));
      assertEquals(clientUpdateResponse.getClaims().get(APPLICATION_TYPE.toString()), registerResponse.getClaims().get(APPLICATION_TYPE.toString()));
      assertEquals(clientUpdateResponse.getClaims().get(SECTOR_IDENTIFIER_URI.toString()), registerResponse.getClaims().get(SECTOR_IDENTIFIER_URI.toString()));
      assertEquals(clientUpdateResponse.getClaims().get(SUBJECT_TYPE.toString()), registerResponse.getClaims().get(SUBJECT_TYPE.toString()));
      assertEquals(clientUpdateResponse.getClaims().get(ID_TOKEN_SIGNED_RESPONSE_ALG.toString()), registerResponse.getClaims().get(ID_TOKEN_SIGNED_RESPONSE_ALG.toString()));
      assertEquals(clientUpdateResponse.getClaims().get(TOKEN_ENDPOINT_AUTH_METHOD.toString()), registerResponse.getClaims().get(TOKEN_ENDPOINT_AUTH_METHOD.toString()));
      assertEquals(clientUpdateResponse.getClaims().get(REQUIRE_AUTH_TIME.toString()), registerResponse.getClaims().get(REQUIRE_AUTH_TIME.toString()));
      assertEquals(clientUpdateResponse.getClaims().get(RPT_AS_JWT.toString()), registerResponse.getClaims().get(RPT_AS_JWT.toString()));
      assertEquals(clientUpdateResponse.getClaims().get(ACCESS_TOKEN_AS_JWT.toString()), registerResponse.getClaims().get(ACCESS_TOKEN_AS_JWT.toString()));
      assertEquals(clientUpdateResponse.getClaims().get(ACCESS_TOKEN_SIGNING_ALG.toString()), registerResponse.getClaims().get(ACCESS_TOKEN_SIGNING_ALG.toString()));
      assertEquals(clientUpdateResponse.getClaims().get(FRONT_CHANNEL_LOGOUT_SESSION_REQUIRED.toString()), registerResponse.getClaims().get(FRONT_CHANNEL_LOGOUT_SESSION_REQUIRED.toString()));

      assertNotNull(clientUpdateResponse.getClaims().get(SCOPE.toString()));
      assertNotNull(registerResponse.getClaims().get(SCOPE.toString()));

      List<String> clientUpdateResponseScopes = Util.splittedStringAsList(clientUpdateResponse.getClaims().get(SCOPE.toString()), " ");
      List<String> registerResponseScopes = Util.splittedStringAsList(registerResponse.getClaims().get(SCOPE.toString()), " ");
      Collections.sort(clientUpdateResponseScopes);
      Collections.sort(registerResponseScopes);
assertEquals(clientUpdateResponseScopes,registerResponseScopes);
  }
 
Example 2
Source File: RegistrationRestWebServiceHttpTest.java    From oxAuth with MIT License 4 votes vote down vote up
@Test(dependsOnMethods = "requestClientAssociate3")
public void requestClientUpdate3() throws Exception {
    showTitle("requestClientUpdate3");

    final String clientName = "Dynamically Registered Client #1 update_1";

    final RegisterRequest registerRequest = new RegisterRequest(registrationAccessToken2);
    registerRequest.setHttpMethod(HttpMethod.PUT);

    registerRequest.setRedirectUris(Arrays.asList("https://localhost:8443/auth"));
    registerRequest.setPostLogoutRedirectUris(Arrays.asList("https://localhost:8443/auth"));
    registerRequest.setApplicationType(ApplicationType.WEB);
    registerRequest.setClientName(clientName);
    registerRequest.setSubjectType(SubjectType.PUBLIC);
    registerRequest.setGrantTypes(Arrays.asList(GrantType.IMPLICIT));
    registerRequest.setResponseTypes(Arrays.asList(ResponseType.TOKEN, ResponseType.ID_TOKEN));
    registerRequest.setScope(Arrays.asList("openid", "address", "profile", "email", "phone", "clientinfo", "invalid_scope"));
    registerRequest.setTokenEndpointAuthMethod(AuthenticationMethod.CLIENT_SECRET_POST);
    registerRequest.setFrontChannelLogoutSessionRequired(true);
    registerRequest.addCustomAttribute("oxAuthTrustedClient", "true");

    final RegisterClient registerClient = new RegisterClient(registrationClientUri2);
    registerClient.setRequest(registerRequest);
    registerClient.setExecutor(clientExecutor(true));
    final RegisterResponse response = registerClient.exec();

    showClient(registerClient);
    assertEquals(response.getStatus(), 200, "Unexpected response code: " + response.getEntity());
    assertNotNull(response.getClientId());

    assertTrue(response.getClaims().containsKey(CLIENT_NAME.toString()));
    assertEquals(clientName, response.getClaims().get(CLIENT_NAME.toString()));
    JSONArray scopesJsonArray = new JSONArray(StringUtils.spaceSeparatedToList(response.getClaims().get(SCOPE.toString())));
    List<String> scopes = new ArrayList<String>();
    for (int i = 0; i < scopesJsonArray.length(); i++) {
        scopes.add(scopesJsonArray.get(i).toString());
    }
    assertTrue(scopes.contains("openid"));
    assertTrue(scopes.contains("address"));
    assertTrue(scopes.contains("email"));
    assertTrue(scopes.contains("profile"));
    assertTrue(scopes.contains("phone"));
    assertTrue(scopes.contains("clientinfo"));
}