Search in sources :

Example 1 with ResourceServer

use of com.auth0.json.mgmt.ResourceServer in project auth0-java by auth0.

the class ResourceServerEntity method delete.

/**
 * Creates request for delete resource server by it's ID
 * See <a href=https://auth0.com/docs/api/management/v2#!/Resource_Servers/delete_resource_servers_by_id>API documentation</a>
 *
 * @param resourceServerId {@link ResourceServer#id} field
 * @return request to execute
 */
public Request<Void> delete(String resourceServerId) {
    Asserts.assertNotNull(resourceServerId, "Resource server ID");
    HttpUrl.Builder builder = baseUrl.newBuilder().addPathSegments("api/v2/resource-servers").addPathSegment(resourceServerId);
    String url = builder.build().toString();
    VoidRequest request = new VoidRequest(client, url, "DELETE");
    request.addHeader("Authorization", "Bearer " + apiToken);
    return request;
}
Also used : VoidRequest(com.auth0.net.VoidRequest) HttpUrl(okhttp3.HttpUrl)

Example 2 with ResourceServer

use of com.auth0.json.mgmt.ResourceServer in project auth0-java by auth0.

the class ResourceServerEntityTest method shouldUpdateResourceServer.

@Test
public void shouldUpdateResourceServer() throws Exception {
    ResourceServer resourceServer = new ResourceServer("https://api.my-company.com/api/v2/");
    resourceServer.setId("23445566abab");
    resourceServer.setName("Some API");
    resourceServer.setScopes(Collections.singletonList(new Scope("update:something")));
    resourceServer.setSigningAlgorithm("RS256");
    resourceServer.setSigningSecret("secret");
    resourceServer.setAllowOfflineAccess(false);
    resourceServer.setEnforcePolicies(true);
    resourceServer.setSkipConsentForVerifiableFirstPartyClients(false);
    resourceServer.setTokenDialect("access_token");
    resourceServer.setTokenLifetime(0);
    resourceServer.setVerificationLocation("verification_location");
    Request<ResourceServer> request = api.resourceServers().update("23445566abab", resourceServer);
    assertThat(request, is(notNullValue()));
    server.jsonResponse(MGMT_RESOURCE_SERVER, 200);
    ResourceServer response = request.execute();
    RecordedRequest recordedRequest = server.takeRequest();
    assertThat(recordedRequest, hasMethodAndPath("PATCH", "/api/v2/resource-servers/23445566abab"));
    assertThat(recordedRequest, hasHeader("Content-Type", "application/json"));
    assertThat(recordedRequest, hasHeader("Authorization", "Bearer apiToken"));
    Map<String, Object> body = bodyFromRequest(recordedRequest);
    assertThat(body.size(), is(12));
    assertThat(body, hasEntry("identifier", "https://api.my-company.com/api/v2/"));
    assertThat(response.getIdentifier(), is("https://api.my-company.com/api/v2/"));
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) Scope(com.auth0.json.mgmt.Scope) ResourceServer(com.auth0.json.mgmt.ResourceServer) Test(org.junit.Test)

Example 3 with ResourceServer

use of com.auth0.json.mgmt.ResourceServer in project auth0-java by auth0.

the class ResourceServerEntityTest method shouldGetResourceServerById.

@Test
public void shouldGetResourceServerById() throws Exception {
    Request<ResourceServer> request = api.resourceServers().get("23445566abab");
    assertThat(request, is(notNullValue()));
    server.jsonResponse(MGMT_RESOURCE_SERVER, 200);
    ResourceServer response = request.execute();
    RecordedRequest recordedRequest = server.takeRequest();
    assertThat(recordedRequest, hasMethodAndPath("GET", "/api/v2/resource-servers/23445566abab"));
    assertThat(recordedRequest, hasHeader("Content-Type", "application/json"));
    assertThat(recordedRequest, hasHeader("Authorization", "Bearer apiToken"));
    assertThat(response.getIdentifier(), is("https://api.my-company.com/api/v2/"));
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) ResourceServer(com.auth0.json.mgmt.ResourceServer) Test(org.junit.Test)

Example 4 with ResourceServer

use of com.auth0.json.mgmt.ResourceServer in project auth0-java by auth0.

the class ResourceServerEntityTest method shouldCreateResourceServer.

@Test
public void shouldCreateResourceServer() throws Exception {
    Request<ResourceServer> request = api.resourceServers().create(new ResourceServer("https://api.my-company.com/api/v2/"));
    assertThat(request, is(notNullValue()));
    server.jsonResponse(MGMT_RESOURCE_SERVER, 200);
    ResourceServer response = request.execute();
    RecordedRequest recordedRequest = server.takeRequest();
    assertThat(recordedRequest, hasMethodAndPath("POST", "/api/v2/resource-servers"));
    assertThat(recordedRequest, hasHeader("Content-Type", "application/json"));
    assertThat(recordedRequest, hasHeader("Authorization", "Bearer apiToken"));
    Map<String, Object> body = bodyFromRequest(recordedRequest);
    assertThat(body.size(), is(1));
    assertThat(body, hasEntry("identifier", "https://api.my-company.com/api/v2/"));
    assertThat(response.getIdentifier(), is("https://api.my-company.com/api/v2/"));
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) ResourceServer(com.auth0.json.mgmt.ResourceServer) Test(org.junit.Test)

Example 5 with ResourceServer

use of com.auth0.json.mgmt.ResourceServer in project auth0-java by auth0.

the class ResourceServerEntityTest method shouldListResourceServers.

@Test
public void shouldListResourceServers() throws Exception {
    @SuppressWarnings("deprecation") Request<List<ResourceServer>> request = api.resourceServers().list();
    assertThat(request, is(notNullValue()));
    server.jsonResponse(MGMT_RESOURCE_SERVERS_LIST, 200);
    List<ResourceServer> response = request.execute();
    RecordedRequest recordedRequest = server.takeRequest();
    assertThat(recordedRequest, hasMethodAndPath("GET", "/api/v2/resource-servers"));
    assertThat(recordedRequest, hasHeader("Content-Type", "application/json"));
    assertThat(recordedRequest, hasHeader("Authorization", "Bearer apiToken"));
    assertThat(response, is(notNullValue()));
    assertThat(response, hasSize(2));
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) List(java.util.List) ResourceServer(com.auth0.json.mgmt.ResourceServer) Test(org.junit.Test)

Aggregations

ResourceServer (com.auth0.json.mgmt.ResourceServer)4 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)4 Test (org.junit.Test)4 Scope (com.auth0.json.mgmt.Scope)1 VoidRequest (com.auth0.net.VoidRequest)1 List (java.util.List)1 HttpUrl (okhttp3.HttpUrl)1