Search in sources :

Example 16 with Scope

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

the class UsersEntity method delete.

/**
 * Delete an existing User.
 * A token with scope delete:users is needed.
 * See https://auth0.com/docs/api/management/v2#!/Users/delete_users_by_id
 *
 * @param userId the user id
 * @return a Request to execute.
 */
public Request<Void> delete(String userId) {
    Asserts.assertNotNull(userId, "user id");
    String url = baseUrl.newBuilder().addPathSegments("api/v2/users").addPathSegment(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 17 with Scope

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

the class RequestProcessorTest method shouldBuildAuthorizeUrl.

@Test
public void shouldBuildAuthorizeUrl() {
    AuthAPI client = new AuthAPI("me.auth0.com", "clientId", "clientSecret");
    SignatureVerifier signatureVerifier = mock(SignatureVerifier.class);
    IdTokenVerifier.Options verifyOptions = new IdTokenVerifier.Options("issuer", "audience", signatureVerifier);
    RequestProcessor handler = new RequestProcessor.Builder(client, "code", verifyOptions).build();
    HttpServletRequest request = new MockHttpServletRequest();
    AuthorizeUrl builder = handler.buildAuthorizeUrl(request, response, "https://redirect.uri/here", "state", "nonce");
    String authorizeUrl = builder.build();
    assertThat(authorizeUrl, is(notNullValue()));
    assertThat(authorizeUrl, CoreMatchers.startsWith("https://me.auth0.com/authorize?"));
    assertThat(authorizeUrl, containsString("client_id=clientId"));
    assertThat(authorizeUrl, containsString("redirect_uri=https://redirect.uri/here"));
    assertThat(authorizeUrl, containsString("response_type=code"));
    assertThat(authorizeUrl, containsString("scope=openid"));
    assertThat(authorizeUrl, containsString("state=state"));
    assertThat(authorizeUrl, not(containsString("max_age=")));
    assertThat(authorizeUrl, not(containsString("nonce=nonce")));
    assertThat(authorizeUrl, not(containsString("response_mode=form_post")));
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) HttpServletRequest(javax.servlet.http.HttpServletRequest) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) AuthAPI(com.auth0.client.auth.AuthAPI) Test(org.junit.jupiter.api.Test)

Example 18 with Scope

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

the class RequestProcessorTest method shouldBuildAuthorizeUrlWithNonceAndFormPostIfResponseTypeIsIdToken.

@Test
public void shouldBuildAuthorizeUrlWithNonceAndFormPostIfResponseTypeIsIdToken() {
    AuthAPI client = new AuthAPI("me.auth0.com", "clientId", "clientSecret");
    RequestProcessor handler = new RequestProcessor.Builder(client, "id_token", verifyOptions).build();
    HttpServletRequest request = new MockHttpServletRequest();
    AuthorizeUrl builder = handler.buildAuthorizeUrl(request, response, "https://redirect.uri/here", "state", "nonce");
    String authorizeUrl = builder.build();
    assertThat(authorizeUrl, is(notNullValue()));
    assertThat(authorizeUrl, CoreMatchers.startsWith("https://me.auth0.com/authorize?"));
    assertThat(authorizeUrl, containsString("client_id=clientId"));
    assertThat(authorizeUrl, containsString("redirect_uri=https://redirect.uri/here"));
    assertThat(authorizeUrl, containsString("response_type=id_token"));
    assertThat(authorizeUrl, containsString("scope=openid"));
    assertThat(authorizeUrl, containsString("state=state"));
    assertThat(authorizeUrl, containsString("nonce=nonce"));
    assertThat(authorizeUrl, containsString("response_mode=form_post"));
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) HttpServletRequest(javax.servlet.http.HttpServletRequest) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) AuthAPI(com.auth0.client.auth.AuthAPI) Test(org.junit.jupiter.api.Test)

Example 19 with Scope

use of com.auth0.json.mgmt.Scope in project localstack-pro-samples by localstack.

the class Test method convert.

public void convert(@NonNull final String token) throws MalformedURLException {
    final URL kidStore = new URL(awsProperties.getCognito().getKidStoreUrl());
    final JwkProvider jwkProvider = new JwkProviderBuilder(kidStore).build();
    final DecodedJWT decodedJWT = JWT.decode(token);
    final AwsCognitoRSAKeyProvider awsCognitoRSAKeyProvider = new AwsCognitoRSAKeyProvider(jwkProvider);
    JWT.require(Algorithm.RSA256(awsCognitoRSAKeyProvider)).acceptLeeway(ACCEPT_LEEWAY_SECONDS).withClaim(TOKEN_USE, ACCESS).build().verify(decodedJWT);
    final Claim clientIdClaim = decodedJWT.getClaim(CLIENT_ID);
    final Claim userNameClaim = decodedJWT.getClaim(USER_NAME);
    final Claim scopeClaim = decodedJWT.getClaim(SCOPE);
    final List<String> roles = Arrays.stream(scopeClaim.asString().split(" ")).map(scope -> scope.substring(scope.lastIndexOf("/") + 1)).collect(Collectors.toList());
    System.out.println("" + clientIdClaim + " " + userNameClaim + " " + roles);
// return new InsureSignToken()
// .setClientId(clientIdClaim.asString())
// .setUserName(userNameClaim.asString())
// .setRoles(roles);
}
Also used : Claim(com.auth0.jwt.Claim) RSAKeyProvider(com.auth0.jwt.interfaces.RSAKeyProvider) JWT(com.auth0.jwt.JWT) Arrays(java.util.Arrays) List(java.util.List) JwkProvider(com.auth0.jwk.JwkProvider) MalformedURLException(java.net.MalformedURLException) URL(java.net.URL) Algorithm(com.auth0.jwt.Algorithm) Collectors(java.util.stream.Collectors) JwkProviderBuilder(com.auth0.jwk.JwkProviderBuilder) JwkProvider(com.auth0.jwk.JwkProvider) JwkProviderBuilder(com.auth0.jwk.JwkProviderBuilder) URL(java.net.URL) Claim(com.auth0.jwt.Claim)

Example 20 with Scope

use of com.auth0.json.mgmt.Scope in project ddf by codice.

the class TestOidc method createAccessToken.

/**
 * Creates an access token
 *
 * @param valid - whether the access token should have a valid signature or not
 * @return an access token to respond to DDF
 */
private String createAccessToken(boolean valid) {
    long exp = Instant.now().plus(Duration.ofDays(3)).toEpochMilli();
    String[] audience = { "master-realm", "account" };
    String[] allowed = { SECURE_ROOT + HTTPS_PORT.getPort() };
    String[] roles = { "create-realm", "offline_access", "admin", "uma_authorization" };
    JSONObject realmAccess = new JSONObject();
    realmAccess.put("roles", ImmutableList.of("create-realm", "offline_access", "admin", "uma_authorization"));
    JSONObject resourceAccess = createMasterRealmJsonObject();
    JWTCreator.Builder builder = JWT.create().withJWTId(UUID.randomUUID().toString()).withExpiresAt(new Date(exp)).withNotBefore(new Date(0)).withIssuedAt(new Date()).withIssuer(URL_START.toString() + "/auth/realms/master").withArrayClaim("aud", audience).withSubject(SUBJECT).withClaim("typ", "Bearer").withClaim(AZP, DDF_CLIENT_ID).withClaim("auth_time", new Date()).withArrayClaim("allowed-origins", allowed).withClaim("realm_access", realmAccess.toString()).withClaim("resource_access", resourceAccess.toString()).withClaim(SCOPE, "openid profile email").withArrayClaim(ROLES, roles).withClaim(EMAIL_VERIFIED, false).withClaim(PREFERRED_USERNAME, ADMIN);
    return valid ? builder.sign(validAlgorithm) : builder.sign(invalidAlgorithm);
}
Also used : JWTCreator(com.auth0.jwt.JWTCreator) JSONObject(org.json.simple.JSONObject) Date(java.util.Date)

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