Search in sources :

Example 11 with Scope

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

the class GrantsEntity method delete.

/**
 * Delete an existing Grant. A token with scope delete:grants is needed.
 * See https://auth0.com/docs/api/management/v2#!/Grants/delete_grants_by_id<br>
 *
 * @param grantId The id of the grant to delete.
 * @return a Request to execute.
 */
public Request<Void> delete(String grantId) {
    Asserts.assertNotNull(grantId, "grant id");
    final String url = baseUrl.newBuilder().addPathSegments("api/v2/grants").addPathSegment(grantId).build().toString();
    VoidRequest request = new VoidRequest(client, url, "DELETE");
    request.addHeader("Authorization", "Bearer " + apiToken);
    return request;
}
Also used : VoidRequest(com.auth0.net.VoidRequest)

Example 12 with Scope

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

the class GrantsEntity method deleteAll.

/**
 * Deletes all Grants of a given user. A token with scope delete:grants is needed.
 * See https://auth0.com/docs/api/management/v2#!/Grants/delete_grants_by_id<br>
 *
 * @param userId The id of the user whose grants are deleted.
 * @return a Request to execute.
 */
public Request<Void> deleteAll(String userId) {
    Asserts.assertNotNull(userId, "user id");
    final String url = baseUrl.newBuilder().addPathSegments("api/v2/grants").addQueryParameter("user_id", userId).build().toString();
    VoidRequest request = new VoidRequest(client, url, "DELETE");
    request.addHeader("Authorization", "Bearer " + apiToken);
    return request;
}
Also used : VoidRequest(com.auth0.net.VoidRequest)

Example 13 with Scope

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

the class ClientGrantsEntityTest method shouldCreateClientGrant.

@Test
public void shouldCreateClientGrant() throws Exception {
    Request<ClientGrant> request = api.clientGrants().create("clientId", "audience", new String[] { "openid" });
    assertThat(request, is(notNullValue()));
    server.jsonResponse(MGMT_CLIENT_GRANT, 200);
    ClientGrant response = request.execute();
    RecordedRequest recordedRequest = server.takeRequest();
    assertThat(recordedRequest, hasMethodAndPath("POST", "/api/v2/client-grants"));
    assertThat(recordedRequest, hasHeader("Content-Type", "application/json"));
    assertThat(recordedRequest, hasHeader("Authorization", "Bearer apiToken"));
    Map<String, Object> body = bodyFromRequest(recordedRequest);
    assertThat(body.size(), is(3));
    assertThat(body, hasEntry("client_id", "clientId"));
    assertThat(body, hasEntry("audience", "audience"));
    assertThat(body, hasKey("scope"));
    assertThat((Iterable<?>) body.get("scope"), contains("openid"));
    assertThat(response, is(notNullValue()));
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) ClientGrant(com.auth0.json.mgmt.ClientGrant) Test(org.junit.Test)

Example 14 with Scope

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

the class ClientGrantsEntityTest method shouldUpdateClientGrant.

@Test
public void shouldUpdateClientGrant() throws Exception {
    Request<ClientGrant> request = api.clientGrants().update("1", new String[] { "openid", "profile" });
    assertThat(request, is(notNullValue()));
    server.jsonResponse(MGMT_CLIENT_GRANT, 200);
    ClientGrant response = request.execute();
    RecordedRequest recordedRequest = server.takeRequest();
    assertThat(recordedRequest, hasMethodAndPath("PATCH", "/api/v2/client-grants/1"));
    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((ArrayList<?>) body.get("scope"), contains("openid", "profile"));
    assertThat(response, is(notNullValue()));
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) ClientGrant(com.auth0.json.mgmt.ClientGrant) Test(org.junit.Test)

Example 15 with Scope

use of com.auth0.json.mgmt.Scope 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)

Aggregations

VoidRequest (com.auth0.net.VoidRequest)24 Test (org.junit.Test)4 AuthAPI (com.auth0.client.auth.AuthAPI)3 Date (java.util.Date)3 HttpServletRequest (javax.servlet.http.HttpServletRequest)3 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)3 Test (org.junit.jupiter.api.Test)3 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)3 ClientGrant (com.auth0.json.mgmt.ClientGrant)2 JWT (com.auth0.jwt.JWT)2 JWTCreator (com.auth0.jwt.JWTCreator)2 Algorithm (com.auth0.jwt.algorithms.Algorithm)2 Arrays (java.util.Arrays)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 JSONObject (org.json.simple.JSONObject)2 ResourceServer (com.auth0.json.mgmt.ResourceServer)1 Scope (com.auth0.json.mgmt.Scope)1 JwkProvider (com.auth0.jwk.JwkProvider)1 JwkProviderBuilder (com.auth0.jwk.JwkProviderBuilder)1