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;
}
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")));
}
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"));
}
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);
}
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);
}
Aggregations