├── settings.gradle ├── src ├── test │ ├── resources │ │ ├── mgmt │ │ │ ├── empty_list.json │ │ │ ├── active_users_count.json │ │ │ ├── guardian_sns_factor_provider_empty.json │ │ │ ├── guardian_twilio_factor_provider_empty.json │ │ │ ├── recovery_code.json │ │ │ ├── scope.json │ │ │ ├── guardian_factor.json │ │ │ ├── guardian_templates.json │ │ │ ├── blacklisted_tokens_list.json │ │ │ ├── post_verification_email.json │ │ │ ├── client_grant.json │ │ │ ├── guardian_twilio_factor_provider_with_from.json │ │ │ ├── guardian_twilio_factor_provider_with_messaging_service_sid.json │ │ │ ├── device_credentials.json │ │ │ ├── daily_stats_list.json │ │ │ ├── email_template.json │ │ │ ├── guardian_enrollment_ticket.json │ │ │ ├── guardian_factors_list.json │ │ │ ├── guardian_sns_factor_provider.json │ │ │ ├── rule.json │ │ │ ├── user_blocks.json │ │ │ ├── connection.json │ │ │ ├── error_with_message.json │ │ │ ├── event_log.json │ │ │ ├── guardian_enrollment.json │ │ │ ├── identities_list.json │ │ │ ├── client_grants_list.json │ │ │ ├── device_credentials_list.json │ │ │ ├── email_provider.json │ │ │ ├── grants_list.json │ │ │ ├── password_change_ticket.json │ │ │ ├── email_verification_ticket.json │ │ │ ├── rules_list.json │ │ │ ├── client_grants_paged_list.json │ │ │ ├── connections_list.json │ │ │ ├── grants_paged_list.json │ │ │ ├── guardian_enrollments_list.json │ │ │ ├── event_logs_list.json │ │ │ ├── rules_paged_list.json │ │ │ ├── resource_server.json │ │ │ ├── connections_paged_list.json │ │ │ ├── event_logs_paged_list.json │ │ │ ├── tenant.json │ │ │ ├── resource_servers_list.json │ │ │ ├── user.json │ │ │ ├── resource_servers_paged_list.json │ │ │ └── client.json │ │ └── auth │ │ │ ├── error_plaintext.json │ │ │ ├── reset_password.json │ │ │ ├── sign_up.json │ │ │ ├── error_with_error_description.json │ │ │ ├── error_with_error.json │ │ │ ├── sign_up_username.json │ │ │ ├── error_with_description.json │ │ │ ├── error_with_description_and_extra_properties.json │ │ │ ├── tokens.json │ │ │ ├── user_info.json │ │ │ ├── password_strength_error_some.json │ │ │ └── password_strength_error_none.json │ └── java │ │ └── com │ │ └── auth0 │ │ ├── json │ │ ├── mgmt │ │ │ ├── userblocks │ │ │ │ ├── UserBlocksTest.java │ │ │ │ └── BlockDetailsTest.java │ │ │ ├── users │ │ │ │ ├── RecoveryCodeTest.java │ │ │ │ ├── IdentityTest.java │ │ │ │ └── ProfileDataTest.java │ │ │ ├── DailyStatsTest.java │ │ │ ├── jobs │ │ │ │ └── JobTest.java │ │ │ ├── ScopeTest.java │ │ │ ├── TokenTest.java │ │ │ ├── guardian │ │ │ │ ├── FactorTest.java │ │ │ │ ├── GuardianTemplatesTest.java │ │ │ │ ├── EnrollmentTest.java │ │ │ │ └── EnrollmentTicketTest.java │ │ │ ├── client │ │ │ │ ├── IOSTest.java │ │ │ │ ├── MobileTest.java │ │ │ │ ├── SigningKeyTest.java │ │ │ │ ├── EncryptionKeyTest.java │ │ │ │ ├── AndroidTest.java │ │ │ │ ├── AddonTest.java │ │ │ │ ├── JWTConfigurationTest.java │ │ │ │ └── AddonsTest.java │ │ │ ├── tenants │ │ │ │ ├── PageCustomizationTest.java │ │ │ │ └── ErrorPageCustomizationTest.java │ │ │ ├── logevents │ │ │ │ └── LogEventTest.java │ │ │ ├── tickets │ │ │ │ ├── EmailVerificationTicketTest.java │ │ │ │ └── PasswordChangeTicketTest.java │ │ │ ├── ClientGrantTest.java │ │ │ ├── GrantTest.java │ │ │ ├── RuleTest.java │ │ │ ├── emailproviders │ │ │ │ └── EmailProviderTest.java │ │ │ ├── DeviceCredentialsTest.java │ │ │ └── EmailTemplateTest.java │ │ ├── auth │ │ │ ├── TokenHolderTest.java │ │ │ └── UserInfoTest.java │ │ └── JsonTest.java │ │ ├── client │ │ └── mgmt │ │ │ ├── BaseMgmtEntityTest.java │ │ │ └── filter │ │ │ ├── ResourceServersFilterTest.java │ │ │ ├── FieldFilterTest.java │ │ │ ├── GrantsFilterTest.java │ │ │ ├── ClientGrantsFilterTest.java │ │ │ ├── RulesFilterTest.java │ │ │ └── DeviceCredentialsFilterTest.java │ │ └── net │ │ ├── TelemetryTest.java │ │ ├── VoidRequestTest.java │ │ └── CreateUserRequestTest.java └── main │ └── java │ └── com │ └── auth0 │ ├── BuildConfig.java │ ├── net │ ├── CustomizableRequest.java │ ├── SignUpRequest.java │ ├── CreateUserRequest.java │ ├── Request.java │ ├── VoidRequest.java │ ├── EmptyBodyRequest.java │ ├── TokenRequest.java │ ├── AuthRequest.java │ ├── BaseRequest.java │ ├── TelemetryInterceptor.java │ └── Telemetry.java │ ├── client │ └── mgmt │ │ ├── filter │ │ ├── BaseFilter.java │ │ ├── FieldsFilter.java │ │ ├── ResourceServersFilter.java │ │ ├── DeviceCredentialsFilter.java │ │ ├── LogEventFilter.java │ │ ├── RulesFilter.java │ │ ├── GrantsFilter.java │ │ ├── ClientGrantsFilter.java │ │ ├── ConnectionFilter.java │ │ ├── ClientFilter.java │ │ ├── UserFilter.java │ │ └── QueryFilter.java │ │ ├── BaseManagementEntity.java │ │ ├── JobsEntity.java │ │ └── BlacklistsEntity.java │ ├── exception │ └── Auth0Exception.java │ ├── json │ ├── mgmt │ │ ├── users │ │ │ ├── RecoveryCode.java │ │ │ ├── UsersPageDeserializer.java │ │ │ ├── UsersPage.java │ │ │ ├── Identity.java │ │ │ └── ProfileData.java │ │ ├── RulesPageDeserializer.java │ │ ├── GrantsPageDeserializer.java │ │ ├── ConnectionsPageDeserializer.java │ │ ├── ClientGrantsPageDeserializer.java │ │ ├── client │ │ │ ├── ClientsPageDeserializer.java │ │ │ ├── Addon.java │ │ │ ├── ClientsPage.java │ │ │ ├── EncryptionKey.java │ │ │ ├── Mobile.java │ │ │ ├── IOS.java │ │ │ ├── Addons.java │ │ │ ├── Android.java │ │ │ └── SigningKey.java │ │ ├── userblocks │ │ │ ├── BlockDetails.java │ │ │ └── UserBlocks.java │ │ ├── logevents │ │ │ ├── LogEventsPageDeserializer.java │ │ │ └── LogEventsPage.java │ │ ├── ResourceServersPageDeserializer.java │ │ ├── RulesPage.java │ │ ├── GrantsPage.java │ │ ├── ConnectionsPage.java │ │ ├── ClientGrantsPage.java │ │ ├── ResourceServersPage.java │ │ ├── Scope.java │ │ ├── DailyStats.java │ │ ├── jobs │ │ │ └── Job.java │ │ ├── tenants │ │ │ ├── PageCustomization.java │ │ │ └── ErrorPageCustomization.java │ │ ├── Token.java │ │ ├── guardian │ │ │ ├── Factor.java │ │ │ └── GuardianTemplates.java │ │ ├── Page.java │ │ ├── PageDeserializer.java │ │ ├── tickets │ │ │ └── EmailVerificationTicket.java │ │ └── ClientGrant.java │ └── auth │ │ ├── UserInfo.java │ │ ├── CreatedUser.java │ │ └── TokenHolder.java │ └── utils │ └── Asserts.java ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── .codecov.yml ├── .circleci └── config.yml ├── LICENSE └── gradlew.bat /settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'auth0' -------------------------------------------------------------------------------- /src/test/resources/mgmt/empty_list.json: -------------------------------------------------------------------------------- 1 | [] -------------------------------------------------------------------------------- /src/test/resources/mgmt/active_users_count.json: -------------------------------------------------------------------------------- 1 | 123 -------------------------------------------------------------------------------- /src/test/resources/mgmt/guardian_sns_factor_provider_empty.json: -------------------------------------------------------------------------------- 1 | {} -------------------------------------------------------------------------------- /src/test/resources/mgmt/guardian_twilio_factor_provider_empty.json: -------------------------------------------------------------------------------- 1 | {} -------------------------------------------------------------------------------- /src/test/resources/auth/error_plaintext.json: -------------------------------------------------------------------------------- 1 | A plain-text error response -------------------------------------------------------------------------------- /src/test/resources/mgmt/recovery_code.json: -------------------------------------------------------------------------------- 1 | { 2 | "recovery_code": "code" 3 | } -------------------------------------------------------------------------------- /src/test/resources/auth/reset_password.json: -------------------------------------------------------------------------------- 1 | We've just sent you an email to reset your password. -------------------------------------------------------------------------------- /src/test/resources/mgmt/scope.json: -------------------------------------------------------------------------------- 1 | { 2 | "description": "Read Client Grants", 3 | "value": "read:client_grants" 4 | } -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/puppetlabs/auth0-java/master/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /src/test/resources/mgmt/guardian_factor.json: -------------------------------------------------------------------------------- 1 | { 2 | "enabled": false, 3 | "trial_expired": false, 4 | "name": "Second" 5 | } -------------------------------------------------------------------------------- /src/test/resources/auth/sign_up.json: -------------------------------------------------------------------------------- 1 | { 2 | "_id": "58457fe6b27", 3 | "email_verified": false, 4 | "email": "me@auth0.com" 5 | } -------------------------------------------------------------------------------- /src/test/resources/mgmt/guardian_templates.json: -------------------------------------------------------------------------------- 1 | { 2 | "enrollment_message": "Enroll using..", 3 | "verification_message": "Verify your number.." 4 | } -------------------------------------------------------------------------------- /src/test/resources/auth/error_with_error_description.json: -------------------------------------------------------------------------------- 1 | { 2 | "error": "invalid_request", 3 | "error_description": "the connection was not found" 4 | } -------------------------------------------------------------------------------- /src/test/resources/auth/error_with_error.json: -------------------------------------------------------------------------------- 1 | { 2 | "error": "missing username for Username-Password-Authentication connection with requires_username enabled" 3 | } -------------------------------------------------------------------------------- /src/test/resources/auth/sign_up_username.json: -------------------------------------------------------------------------------- 1 | { 2 | "_id": "58457fe6b27", 3 | "email_verified": false, 4 | "email": "me@auth0.com", 5 | "username": "me" 6 | } -------------------------------------------------------------------------------- /src/main/java/com/auth0/BuildConfig.java: -------------------------------------------------------------------------------- 1 | package com.auth0; 2 | 3 | public interface BuildConfig { 4 | String NAME = "auth0-java"; 5 | String VERSION = "1.0.0"; 6 | } 7 | -------------------------------------------------------------------------------- /src/test/resources/mgmt/blacklisted_tokens_list.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "aud": "1", 4 | "jti": "1" 5 | }, 6 | { 7 | "aud": "2", 8 | "jti": "2" 9 | } 10 | ] -------------------------------------------------------------------------------- /src/test/resources/mgmt/post_verification_email.json: -------------------------------------------------------------------------------- 1 | { 2 | "status": "completed", 3 | "type": "verification_email", 4 | "created_at": "", 5 | "id": "job_0000000000000001" 6 | } -------------------------------------------------------------------------------- /src/test/resources/auth/error_with_description.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "BadRequestError", 3 | "code": "user_exists", 4 | "description": "The user already exists.", 5 | "statusCode": 400 6 | } -------------------------------------------------------------------------------- /src/test/resources/mgmt/client_grant.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": "1", 3 | "client_id": "clientId1", 4 | "audience": "audience1", 5 | "scope": [ 6 | "openid", 7 | "profile" 8 | ] 9 | } -------------------------------------------------------------------------------- /src/test/resources/mgmt/guardian_twilio_factor_provider_with_from.json: -------------------------------------------------------------------------------- 1 | { 2 | "from": "+156789", 3 | "messaging_service_sid": null, 4 | "auth_token": "aToKen", 5 | "sid": "3123" 6 | } -------------------------------------------------------------------------------- /src/test/resources/mgmt/guardian_twilio_factor_provider_with_messaging_service_sid.json: -------------------------------------------------------------------------------- 1 | { 2 | "from": null, 3 | "messaging_service_sid": "aac", 4 | "auth_token": "aToKen", 5 | "sid": "3123" 6 | } -------------------------------------------------------------------------------- /src/test/resources/auth/error_with_description_and_extra_properties.json: -------------------------------------------------------------------------------- 1 | { 2 | "error": "mfa_required", 3 | "error_description": "Multifactor authentication required", 4 | "mfa_token": "Fe26...Ha" 5 | } -------------------------------------------------------------------------------- /src/test/resources/mgmt/device_credentials.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": "dcr_0INpgifmKRm5z", 3 | "device_name": "Google Nexus 5X - 6.0.0 - API 23 - 1080x1920", 4 | "user_id": "auth0|121212", 5 | "type": "refresh_token" 6 | } -------------------------------------------------------------------------------- /src/test/resources/auth/tokens.json: -------------------------------------------------------------------------------- 1 | { 2 | "id_token": "eyJ0eXAiOiJKV1Qi...", 3 | "access_token": "A9CvPwFojaBI...", 4 | "refresh_token": "GEbRxBN...edjnXbL", 5 | "token_type": "bearer", 6 | "expires_in": 86000 7 | } -------------------------------------------------------------------------------- /src/test/resources/mgmt/daily_stats_list.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "date": "2014-01-01T05:00:00.000Z", 4 | "logins": 100 5 | }, 6 | { 7 | "date": "2014-01-01T05:00:00.000Z", 8 | "logins": 100 9 | } 10 | ] -------------------------------------------------------------------------------- /src/test/resources/mgmt/email_template.json: -------------------------------------------------------------------------------- 1 | { 2 | "template": "welcome_email", 3 | "from": "me@auth0.com", 4 | "subject": "Some subject", 5 | "syntax": "liquid", 6 | "body": " ", 7 | "enabled": false 8 | } -------------------------------------------------------------------------------- /src/test/resources/mgmt/guardian_enrollment_ticket.json: -------------------------------------------------------------------------------- 1 | { 2 | "user_id": "u123", 3 | "email": "me@auth0.com", 4 | "send_mail": false, 5 | "ticket_id": "12345679", 6 | "ticket_url": "https://auth0.com/guardian/tickets/123" 7 | } -------------------------------------------------------------------------------- /src/test/resources/mgmt/guardian_factors_list.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "enabled": true, 4 | "trial_expired": true, 5 | "name": "First" 6 | }, 7 | { 8 | "enabled": false, 9 | "trial_expired": false, 10 | "name": "Second" 11 | } 12 | ] -------------------------------------------------------------------------------- /src/test/resources/mgmt/guardian_sns_factor_provider.json: -------------------------------------------------------------------------------- 1 | { 2 | "aws_access_key_id": "123123132", 3 | "aws_secret_access_key": "aac", 4 | "aws_region": "us", 5 | "sns_apns_platform_application_arn": "132", 6 | "sns_gcm_platform_application_arn": "3123" 7 | } -------------------------------------------------------------------------------- /src/test/resources/mgmt/rule.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "rule_1", 3 | "id": "con_0000000000000001", 4 | "enabled": true, 5 | "script": "function (user, context, callback) {\n callback(null, user, context);\n}", 6 | "order": 1, 7 | "stage": "login_success" 8 | } -------------------------------------------------------------------------------- /src/test/resources/mgmt/user_blocks.json: -------------------------------------------------------------------------------- 1 | { 2 | "blocked_for": [ 3 | { 4 | "identifier": "john.doe@gmail.com", 5 | "ip": "10.0.0.1" 6 | }, 7 | { 8 | "identifier": "john.doe@gmail.com", 9 | "ip": "10.0.0.2" 10 | } 11 | ] 12 | } -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Tue Jan 03 13:42:16 ART 2017 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-3.5-all.zip 7 | -------------------------------------------------------------------------------- /src/test/resources/mgmt/connection.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "My connection1", 3 | "options": {}, 4 | "id": "con_0000000000000001", 5 | "strategy": "auth0", 6 | "enabled_clients": [ 7 | "avUAvH1pgnZGgAGlv8guZLPoaOnjVJsM", 8 | "ScKKdrpyUwfkhOQP6KXItH32INgZf7Rb" 9 | ] 10 | } -------------------------------------------------------------------------------- /.codecov.yml: -------------------------------------------------------------------------------- 1 | coverage: 2 | precision: 2 3 | round: down 4 | range: "70...100" 5 | status: 6 | patch: 7 | default: 8 | if_no_uploads: error 9 | changes: true 10 | project: 11 | default: 12 | target: auto 13 | if_no_uploads: error 14 | comment: false -------------------------------------------------------------------------------- /src/test/resources/mgmt/error_with_message.json: -------------------------------------------------------------------------------- 1 | { 2 | "statusCode": 400, 3 | "error": "Bad Request", 4 | "message": "Query validation error: 'String 'invalid_field' does not match pattern. Must be a comma separated list of the following values: allowed_logout_urls,change_password.", 5 | "errorCode": "invalid_query_string" 6 | } -------------------------------------------------------------------------------- /src/test/resources/mgmt/event_log.json: -------------------------------------------------------------------------------- 1 | { 2 | "date": "2016-02-23T19:57:29.532Z", 3 | "type": "sapi", 4 | "client_id": "AaiyAPdpYdesoKnqjj8HJqRn4T5titww", 5 | "client_name": "My Game", 6 | "ip": "190.257.209.19", 7 | "location_info": {}, 8 | "details": {}, 9 | "user_id": "auth0|56c75c4e42b6359e98374bc2" 10 | } -------------------------------------------------------------------------------- /src/test/resources/mgmt/guardian_enrollment.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": "dev_3213TGOhu0ea", 3 | "status": "confirmed", 4 | "type": "pn", 5 | "name": "Nexus 5X", 6 | "phone_number": null, 7 | "identifier": "f491f858432059", 8 | "enrolled_at": "2017-01-18T17:45:08.328Z", 9 | "auth_method": "", 10 | "last_auth": "2017-07-12T17:56:26.804Z" 11 | } -------------------------------------------------------------------------------- /src/main/java/com/auth0/net/CustomizableRequest.java: -------------------------------------------------------------------------------- 1 | package com.auth0.net; 2 | 3 | interface CustomizableRequest extends Request { 4 | 5 | CustomizableRequest addHeader(String name, String value); 6 | 7 | CustomizableRequest addParameter(String name, Object value); 8 | 9 | CustomizableRequest setBody(Object body); 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/com/auth0/client/mgmt/filter/BaseFilter.java: -------------------------------------------------------------------------------- 1 | package com.auth0.client.mgmt.filter; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | public abstract class BaseFilter { 7 | protected Map parameters = new HashMap<>(); 8 | 9 | public Map getAsMap() { 10 | return parameters; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/test/resources/mgmt/identities_list.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "connection": "Someconnetion", 4 | "user_id": "5457edea1b8f22891a000002", 5 | "provider": "facebook", 6 | "isSocial": true 7 | }, 8 | { 9 | "connection": "Initial-Connection", 10 | "user_id": "5457edea1b8f22891a000004", 11 | "provider": "auth0", 12 | "isSocial": false 13 | } 14 | ] -------------------------------------------------------------------------------- /src/test/resources/mgmt/client_grants_list.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "id": "1", 4 | "client_id": "clientId1", 5 | "audience": "audience1", 6 | "scope": [ 7 | "openid", 8 | "profile" 9 | ] 10 | }, 11 | { 12 | "id": "2", 13 | "client_id": "clientId2", 14 | "audience": "audience2", 15 | "scope": [ 16 | "openid", 17 | "profile" 18 | ] 19 | } 20 | ] -------------------------------------------------------------------------------- /src/test/resources/mgmt/device_credentials_list.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "id": "dcr_03YxCFDQfS7RT", 4 | "device_name": "Google Nexus 4 - 5.1.0 - API 22 - 768x1280", 5 | "user_id": "twitter|323232", 6 | "type": "refresh_token" 7 | }, 8 | { 9 | "id": "dcr_0INpgifmKRm5z", 10 | "device_name": "Google Nexus 5X - 6.0.0 - API 23 - 1080x1920", 11 | "user_id": "auth0|121212", 12 | "type": "refresh_token" 13 | } 14 | ] -------------------------------------------------------------------------------- /src/test/resources/mgmt/email_provider.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "sendgrid", 3 | "enabled": true, 4 | "default_from_address": "", 5 | "credentials": { 6 | "api_user": "", 7 | "api_key": "your_mandrill_api_key", 8 | "accessKeyId": "", 9 | "secretAccessKey": "", 10 | "region": "", 11 | "smtp_host": "", 12 | "smtp_port": 0, 13 | "smtp_user": "", 14 | "smtp_pass": "" 15 | }, 16 | "settings": {} 17 | } -------------------------------------------------------------------------------- /src/test/resources/mgmt/grants_list.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "id": "1", 4 | "clientID": "clientId1", 5 | "audience": "audience1", 6 | "user_id": "userId", 7 | "scope": [ 8 | "openid", 9 | "profile" 10 | ] 11 | }, 12 | { 13 | "id": "2", 14 | "clientID": "clientId2", 15 | "user_id": "userId", 16 | "audience": "audience2", 17 | "scope": [ 18 | "openid", 19 | "profile" 20 | ] 21 | } 22 | ] -------------------------------------------------------------------------------- /src/test/resources/mgmt/password_change_ticket.json: -------------------------------------------------------------------------------- 1 | { 2 | "ticket": "https://login.auth0.com/lo/verify_email?client_id=nsaPS2p3cargoFy82WT7betaOPOt3qSh&tenant=mdocs&bewit=bmNlR01CcDNOUE1GeXVzODJXVDdyY1RUT1BPdDNxU2hcMTQzMDY2MjE4MVxuRTcxM0RSeUNlbEpzUUJmaFVaS3A1NEdJbWFzSUZMYzRTdEFtY2NMMXhZPVx7ImVtYWloojoiZGFtaWtww2NoQGhvdG1haWwuY29tIiwidGVuYW50IjoiZHNjaGVua2tjwWFuIiwiY2xpZW50X2lkIjoibmNlR01CcDNOUE1GeXVzODJXVDdyY1RUT1BPiiqxU2giLCJjb25uZWN0aW9uIjoiRGFtaWmsdiwicmVzdWx0VXJsIjoiIn0" 3 | } -------------------------------------------------------------------------------- /src/test/resources/mgmt/email_verification_ticket.json: -------------------------------------------------------------------------------- 1 | { 2 | "ticket": "https://login.auth0.com/lo/verify_email?client_id=nsaPS2p3cargoFy82WT7betaOPOt3qSh&tenant=mdocs&bewit=bmNlR01CcDNOUE1GeXVzODJXVDdyY1RUT1BPdDNxU2hcMTQzMDY2MjE4MVxuRTcxM0RSeUNlbEpzUUJmaFVaS3A1NEdJbWFzSUZMYzRTdEFtY2NMMXhZPVx7ImVtYWloojoiZGFtaWtww2NoQGhvdG1haWwuY29tIiwidGVuYW50IjoiZHNjaGVua2tjwWFuIiwiY2xpZW50X2lkIjoibmNlR01CcDNOUE1GeXVzODJXVDdyY1RUT1BPiiqxU2giLCJjb25uZWN0aW9uIjoiRGFtaWmsdiwicmVzdWx0VXJsIjoiIn0" 3 | } -------------------------------------------------------------------------------- /src/main/java/com/auth0/client/mgmt/BaseManagementEntity.java: -------------------------------------------------------------------------------- 1 | package com.auth0.client.mgmt; 2 | 3 | import okhttp3.HttpUrl; 4 | import okhttp3.OkHttpClient; 5 | 6 | abstract class BaseManagementEntity { 7 | protected final OkHttpClient client; 8 | protected final HttpUrl baseUrl; 9 | protected final String apiToken; 10 | 11 | BaseManagementEntity(OkHttpClient client, HttpUrl baseUrl, String apiToken) { 12 | this.client = client; 13 | this.baseUrl = baseUrl; 14 | this.apiToken = apiToken; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/com/auth0/exception/Auth0Exception.java: -------------------------------------------------------------------------------- 1 | package com.auth0.exception; 2 | 3 | import java.io.IOException; 4 | 5 | /** 6 | * Class that represents an error captured when executing an http request to the Auth0 Server. 7 | */ 8 | @SuppressWarnings("WeakerAccess") 9 | public class Auth0Exception extends IOException { 10 | 11 | public Auth0Exception(String message) { 12 | super(message); 13 | } 14 | 15 | public Auth0Exception(String message, Throwable cause) { 16 | super(message, cause); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/test/resources/mgmt/rules_list.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "name": "rule_1", 4 | "id": "con_0000000000000001", 5 | "enabled": true, 6 | "script": "function (user, context, callback) {\n callback(null, user, context);\n}", 7 | "order": 1, 8 | "stage": "login_success" 9 | }, 10 | { 11 | "name": "rule_2", 12 | "id": "con_0000000000000002", 13 | "enabled": true, 14 | "script": "function (user, context, callback) {\n callback(null, user, context);\n}", 15 | "order": 1, 16 | "stage": "login_success" 17 | } 18 | ] -------------------------------------------------------------------------------- /src/test/resources/mgmt/client_grants_paged_list.json: -------------------------------------------------------------------------------- 1 | { 2 | "start": 0, 3 | "length": 14, 4 | "total": 14, 5 | "limit": 50, 6 | "client_grants": [ 7 | { 8 | "id": "1", 9 | "client_id": "clientId1", 10 | "audience": "audience1", 11 | "scope": [ 12 | "openid", 13 | "profile" 14 | ] 15 | }, 16 | { 17 | "id": "2", 18 | "client_id": "clientId2", 19 | "audience": "audience2", 20 | "scope": [ 21 | "openid", 22 | "profile" 23 | ] 24 | } 25 | ] 26 | } -------------------------------------------------------------------------------- /src/test/resources/mgmt/connections_list.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "name": "My connection1", 4 | "options": {}, 5 | "id": "con_0000000000000001", 6 | "strategy": "auth0", 7 | "enabled_clients": [ 8 | "avUAvH1pgnZGgAGlv8guZLPoaOnjVJsM", 9 | "ScKKdrpyUwfkhOQP6KXItH32INgZf7Rb" 10 | ] 11 | }, 12 | { 13 | "name": "My connection2", 14 | "options": {}, 15 | "id": "con_0000000000000002", 16 | "strategy": "auth0", 17 | "enabled_clients": [ 18 | "avUAvH1pgnZGgAGlv8guZLPoaOnjVJsM", 19 | "ScKKdrpyUwfkhOQP6KXItH32INgZf7Rb" 20 | ] 21 | } 22 | ] -------------------------------------------------------------------------------- /src/test/resources/mgmt/grants_paged_list.json: -------------------------------------------------------------------------------- 1 | { 2 | "start": 0, 3 | "length": 14, 4 | "total": 14, 5 | "limit": 50, 6 | "grants": [ 7 | { 8 | "id": "1", 9 | "clientID": "clientId1", 10 | "audience": "audience1", 11 | "user_id": "userId", 12 | "scope": [ 13 | "openid", 14 | "profile" 15 | ] 16 | }, 17 | { 18 | "id": "2", 19 | "clientID": "clientId2", 20 | "user_id": "userId", 21 | "audience": "audience2", 22 | "scope": [ 23 | "openid", 24 | "profile" 25 | ] 26 | } 27 | ] 28 | } -------------------------------------------------------------------------------- /src/main/java/com/auth0/net/SignUpRequest.java: -------------------------------------------------------------------------------- 1 | package com.auth0.net; 2 | 3 | import com.auth0.json.auth.CreatedUser; 4 | 5 | import java.util.Map; 6 | 7 | /** 8 | * Class that represents a Create User call. 9 | */ 10 | @SuppressWarnings("UnusedReturnValue") 11 | public interface SignUpRequest extends Request { 12 | 13 | /** 14 | * Setter for the additional fields to set when creating a user. 15 | * 16 | * @param customFields the list of custom fields. 17 | * @return this request instance. 18 | */ 19 | SignUpRequest setCustomFields(Map customFields); 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/com/auth0/json/mgmt/users/RecoveryCode.java: -------------------------------------------------------------------------------- 1 | package com.auth0.json.mgmt.users; 2 | 3 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 4 | import com.fasterxml.jackson.annotation.JsonInclude; 5 | import com.fasterxml.jackson.annotation.JsonProperty; 6 | 7 | @SuppressWarnings("unused") 8 | @JsonIgnoreProperties(ignoreUnknown = true) 9 | @JsonInclude(JsonInclude.Include.NON_NULL) 10 | public class RecoveryCode { 11 | 12 | @JsonProperty("recovery_code") 13 | private String code; 14 | 15 | @JsonProperty("recovery_code") 16 | public String getCode() { 17 | return code; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/test/resources/auth/user_info.json: -------------------------------------------------------------------------------- 1 | { 2 | "email_verified": false, 3 | "email": "test.account@userinfo.com", 4 | "clientID": "q2hnj2iu...", 5 | "updated_at": "2016-12-05T15:15:40.545Z", 6 | "name": "test.account@userinfo.com", 7 | "picture": "https://s.gravatar.com/avatar/dummy.png", 8 | "user_id": "auth0|58454...", 9 | "nickname": "test.account", 10 | "identities": [ 11 | { 12 | "user_id": "58454...", 13 | "provider": "auth0", 14 | "connection": "Username-Password-Authentication", 15 | "isSocial": false 16 | } 17 | ], 18 | "created_at": "2016-12-05T11:16:59.640Z", 19 | "sub": "auth0|58454..." 20 | } -------------------------------------------------------------------------------- /src/test/resources/mgmt/guardian_enrollments_list.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "id": "dev_3213TGOhu0ea", 4 | "status": "confirmed", 5 | "type": "pn", 6 | "name": "Nexus 5X", 7 | "phone_number": null, 8 | "identifier": "f491f858432059", 9 | "enrolled_at": "2017-01-18T17:45:08.328Z", 10 | "auth_method": "", 11 | "last_auth": "" 12 | }, 13 | { 14 | "id": "dev_3213TGOhu0ea", 15 | "status": "confirmed", 16 | "type": "pn", 17 | "name": "Nexus 5X", 18 | "phone_number": null, 19 | "identifier": "f491f858432059", 20 | "enrolled_at": "2017-01-18T17:45:08.328Z", 21 | "auth_method": "", 22 | "last_auth": "" 23 | } 24 | ] -------------------------------------------------------------------------------- /src/test/resources/mgmt/event_logs_list.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "date": "2016-02-23T19:57:29.532Z", 4 | "type": "sapi", 5 | "client_id": "AaiyAPdpYdesoKnqjj8HJqRn4T5titww", 6 | "client_name": "My Game", 7 | "ip": "190.257.209.19", 8 | "location_info": {}, 9 | "details": {}, 10 | "user_id": "auth0|56c75c4e42b6359e98374bc2" 11 | }, 12 | { 13 | "date": "2016-03-23T19:57:31.532Z", 14 | "type": "lapi", 15 | "client_id": "AaiyAPdpYdesoKnqjj8HJqRn4T5titww", 16 | "client_name": "My Application", 17 | "ip": "190.257.209.29", 18 | "location_info": {}, 19 | "details": {}, 20 | "user_id": "auth0|56c75c4e42b6359e98374bc2" 21 | } 22 | ] -------------------------------------------------------------------------------- /src/test/resources/mgmt/rules_paged_list.json: -------------------------------------------------------------------------------- 1 | { 2 | "start": 0, 3 | "length": 14, 4 | "total": 14, 5 | "limit": 50, 6 | "rules": [ 7 | { 8 | "name": "rule_1", 9 | "id": "con_0000000000000001", 10 | "enabled": true, 11 | "script": "function (user, context, callback) {\n callback(null, user, context);\n}", 12 | "order": 1, 13 | "stage": "login_success" 14 | }, 15 | { 16 | "name": "rule_2", 17 | "id": "con_0000000000000002", 18 | "enabled": true, 19 | "script": "function (user, context, callback) {\n callback(null, user, context);\n}", 20 | "order": 1, 21 | "stage": "login_success" 22 | } 23 | ] 24 | } -------------------------------------------------------------------------------- /src/main/java/com/auth0/utils/Asserts.java: -------------------------------------------------------------------------------- 1 | package com.auth0.utils; 2 | 3 | import okhttp3.HttpUrl; 4 | 5 | public abstract class Asserts { 6 | public static void assertNotNull(Object value, String name) throws IllegalArgumentException { 7 | if (value == null) { 8 | throw new IllegalArgumentException(String.format("'%s' cannot be null!", name)); 9 | } 10 | } 11 | 12 | public static void assertValidUrl(String value, String name) throws IllegalArgumentException { 13 | if (value == null || HttpUrl.parse(value) == null) { 14 | throw new IllegalArgumentException(String.format("'%s' must be a valid URL!", name)); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/com/auth0/json/mgmt/RulesPageDeserializer.java: -------------------------------------------------------------------------------- 1 | package com.auth0.json.mgmt; 2 | 3 | import java.util.List; 4 | 5 | @SuppressWarnings({"unused", "WeakerAccess"}) 6 | class RulesPageDeserializer extends PageDeserializer { 7 | 8 | RulesPageDeserializer() { 9 | super(Rule.class, "rules"); 10 | } 11 | 12 | @Override 13 | protected RulesPage createPage(List items) { 14 | return new RulesPage(items); 15 | } 16 | 17 | @Override 18 | protected RulesPage createPage(Integer start, Integer length, Integer total, Integer limit, List items) { 19 | return new RulesPage(start, length, total, limit, items); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/com/auth0/json/mgmt/GrantsPageDeserializer.java: -------------------------------------------------------------------------------- 1 | package com.auth0.json.mgmt; 2 | 3 | import java.util.List; 4 | 5 | @SuppressWarnings({"unused", "WeakerAccess"}) 6 | class GrantsPageDeserializer extends PageDeserializer { 7 | 8 | GrantsPageDeserializer() { 9 | super(Grant.class, "grants"); 10 | } 11 | 12 | @Override 13 | protected GrantsPage createPage(List items) { 14 | return new GrantsPage(items); 15 | } 16 | 17 | @Override 18 | protected GrantsPage createPage(Integer start, Integer length, Integer total, Integer limit, List items) { 19 | return new GrantsPage(start, length, total, limit, items); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /src/test/resources/mgmt/resource_server.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": "23445566abab", 3 | "name": "Some API", 4 | "identifier": "https://api.my-company.com/api/v2/", 5 | "signing_alg": "RS256", 6 | "token_lifetime": 86400, 7 | "token_lifetime_for_web": 7200, 8 | "allow_offline_access": false, 9 | "skip_consent_for_verifiable_first_party_clients": false, 10 | "signing_secret":"secret", 11 | "verification_location":"verification_location", 12 | "scopes": [ 13 | { 14 | "description": "Read Client Grants", 15 | "value": "read:client_grants" 16 | }, 17 | { 18 | "description": "Create Client Grants", 19 | "value": "create:client_grants" 20 | } 21 | ], 22 | "is_system": true 23 | } -------------------------------------------------------------------------------- /src/main/java/com/auth0/net/CreateUserRequest.java: -------------------------------------------------------------------------------- 1 | package com.auth0.net; 2 | 3 | import com.auth0.json.auth.CreatedUser; 4 | import com.fasterxml.jackson.core.type.TypeReference; 5 | import okhttp3.OkHttpClient; 6 | 7 | import java.util.Map; 8 | 9 | public class CreateUserRequest extends CustomRequest implements SignUpRequest { 10 | 11 | public CreateUserRequest(OkHttpClient client, String url) { 12 | super(client, url, "POST", new TypeReference() { 13 | }); 14 | } 15 | 16 | @Override 17 | public SignUpRequest setCustomFields(Map customFields) { 18 | super.addParameter("user_metadata", customFields); 19 | return this; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/com/auth0/net/Request.java: -------------------------------------------------------------------------------- 1 | package com.auth0.net; 2 | 3 | import com.auth0.exception.APIException; 4 | import com.auth0.exception.Auth0Exception; 5 | 6 | /** 7 | * Class that represents an HTTP Request that can be executed. 8 | * 9 | * @param the type of payload expected in the response after the execution. 10 | */ 11 | public interface Request { 12 | 13 | /** 14 | * Executes this request. 15 | * 16 | * @return the response body JSON decoded as T 17 | * @throws APIException if the request was executed but the response wasn't successful. 18 | * @throws Auth0Exception if the request couldn't be created or executed successfully. 19 | */ 20 | T execute() throws Auth0Exception; 21 | } 22 | -------------------------------------------------------------------------------- /src/test/resources/mgmt/connections_paged_list.json: -------------------------------------------------------------------------------- 1 | { 2 | "start": 0, 3 | "length": 14, 4 | "total": 14, 5 | "limit": 50, 6 | "connections": [ 7 | { 8 | "name": "My connection1", 9 | "options": {}, 10 | "id": "con_0000000000000001", 11 | "strategy": "auth0", 12 | "enabled_clients": [ 13 | "avUAvH1pgnZGgAGlv8guZLPoaOnjVJsM", 14 | "ScKKdrpyUwfkhOQP6KXItH32INgZf7Rb" 15 | ] 16 | }, 17 | { 18 | "name": "My connection2", 19 | "options": {}, 20 | "id": "con_0000000000000002", 21 | "strategy": "auth0", 22 | "enabled_clients": [ 23 | "avUAvH1pgnZGgAGlv8guZLPoaOnjVJsM", 24 | "ScKKdrpyUwfkhOQP6KXItH32INgZf7Rb" 25 | ] 26 | } 27 | ] 28 | } 29 | -------------------------------------------------------------------------------- /src/test/java/com/auth0/json/mgmt/userblocks/UserBlocksTest.java: -------------------------------------------------------------------------------- 1 | package com.auth0.json.mgmt.userblocks; 2 | 3 | import com.auth0.json.JsonTest; 4 | import org.junit.Test; 5 | 6 | import static org.hamcrest.MatcherAssert.assertThat; 7 | import static org.hamcrest.Matchers.*; 8 | 9 | public class UserBlocksTest extends JsonTest { 10 | 11 | private static final String json = "{\"blocked_for\":[{},{}]}"; 12 | 13 | @Test 14 | public void shouldDeserialize() throws Exception { 15 | UserBlocks blocks = fromJSON(json, UserBlocks.class); 16 | 17 | assertThat(blocks, is(notNullValue())); 18 | assertThat(blocks.getBlockedFor(), is(notNullValue())); 19 | assertThat(blocks.getBlockedFor(), hasSize(2)); 20 | } 21 | } -------------------------------------------------------------------------------- /src/test/java/com/auth0/json/mgmt/users/RecoveryCodeTest.java: -------------------------------------------------------------------------------- 1 | package com.auth0.json.mgmt.users; 2 | 3 | import com.auth0.json.JsonTest; 4 | import org.junit.Test; 5 | 6 | import static org.hamcrest.MatcherAssert.assertThat; 7 | import static org.hamcrest.Matchers.is; 8 | import static org.hamcrest.Matchers.notNullValue; 9 | 10 | public class RecoveryCodeTest extends JsonTest { 11 | 12 | private static final String json = "{\"recovery_code\":\"supersecretCODE\"}"; 13 | 14 | @Test 15 | public void shouldDeserialize() throws Exception { 16 | RecoveryCode code = fromJSON(json, RecoveryCode.class); 17 | 18 | assertThat(code, is(notNullValue())); 19 | assertThat(code.getCode(), is("supersecretCODE")); 20 | } 21 | } -------------------------------------------------------------------------------- /src/main/java/com/auth0/json/mgmt/users/UsersPageDeserializer.java: -------------------------------------------------------------------------------- 1 | package com.auth0.json.mgmt.users; 2 | 3 | import com.auth0.json.mgmt.PageDeserializer; 4 | 5 | import java.util.List; 6 | 7 | @SuppressWarnings({"unused", "WeakerAccess"}) 8 | class UsersPageDeserializer extends PageDeserializer { 9 | 10 | UsersPageDeserializer() { 11 | super(User.class, "users"); 12 | } 13 | 14 | @Override 15 | protected UsersPage createPage(List items) { 16 | return new UsersPage(items); 17 | } 18 | 19 | @Override 20 | protected UsersPage createPage(Integer start, Integer length, Integer total, Integer limit, List items) { 21 | return new UsersPage(start, length, total, limit, items); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/com/auth0/net/VoidRequest.java: -------------------------------------------------------------------------------- 1 | package com.auth0.net; 2 | 3 | import com.auth0.exception.Auth0Exception; 4 | import com.fasterxml.jackson.core.type.TypeReference; 5 | import okhttp3.OkHttpClient; 6 | import okhttp3.Response; 7 | 8 | public class VoidRequest extends CustomRequest { 9 | 10 | public VoidRequest(OkHttpClient client, String url, String method) { 11 | super(client, url, method, new TypeReference() { 12 | }); 13 | } 14 | 15 | @Override 16 | protected Void parseResponse(Response response) throws Auth0Exception { 17 | if (!response.isSuccessful()) { 18 | throw super.createResponseException(response); 19 | } 20 | response.close(); 21 | return null; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/com/auth0/json/mgmt/ConnectionsPageDeserializer.java: -------------------------------------------------------------------------------- 1 | package com.auth0.json.mgmt; 2 | 3 | import java.util.List; 4 | 5 | @SuppressWarnings({"unused", "WeakerAccess"}) 6 | class ConnectionsPageDeserializer extends PageDeserializer { 7 | 8 | ConnectionsPageDeserializer() { 9 | super(Connection.class, "connections"); 10 | } 11 | 12 | @Override 13 | protected ConnectionsPage createPage(List items) { 14 | return new ConnectionsPage(items); 15 | } 16 | 17 | @Override 18 | protected ConnectionsPage createPage(Integer start, Integer length, Integer total, Integer limit, List items) { 19 | return new ConnectionsPage(start, length, total, limit, items); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/com/auth0/client/mgmt/filter/FieldsFilter.java: -------------------------------------------------------------------------------- 1 | package com.auth0.client.mgmt.filter; 2 | 3 | /** 4 | * Class used to filter the results received when calling an Auth0 endpoint. 5 | */ 6 | public class FieldsFilter extends BaseFilter { 7 | 8 | /** 9 | * Only retrieve certain fields from the item. 10 | * 11 | * @param fields a list of comma separated fields to retrieve. 12 | * @param includeFields whether to include or exclude in the response the fields that were given. 13 | * @return this filter instance 14 | */ 15 | public FieldsFilter withFields(String fields, boolean includeFields) { 16 | parameters.put("fields", fields); 17 | parameters.put("include_fields", includeFields); 18 | return this; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/com/auth0/json/mgmt/ClientGrantsPageDeserializer.java: -------------------------------------------------------------------------------- 1 | package com.auth0.json.mgmt; 2 | 3 | import java.util.List; 4 | 5 | @SuppressWarnings({"unused", "WeakerAccess"}) 6 | class ClientGrantsPageDeserializer extends PageDeserializer { 7 | 8 | ClientGrantsPageDeserializer() { 9 | super(ClientGrant.class, "client_grants"); 10 | } 11 | 12 | @Override 13 | protected ClientGrantsPage createPage(List items) { 14 | return new ClientGrantsPage(items); 15 | } 16 | 17 | @Override 18 | protected ClientGrantsPage createPage(Integer start, Integer length, Integer total, Integer limit, List items) { 19 | return new ClientGrantsPage(start, length, total, limit, items); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/com/auth0/json/mgmt/client/ClientsPageDeserializer.java: -------------------------------------------------------------------------------- 1 | package com.auth0.json.mgmt.client; 2 | 3 | import com.auth0.json.mgmt.PageDeserializer; 4 | 5 | import java.util.List; 6 | 7 | @SuppressWarnings({"unused", "WeakerAccess"}) 8 | class ClientsPageDeserializer extends PageDeserializer { 9 | 10 | ClientsPageDeserializer() { 11 | super(Client.class, "clients"); 12 | } 13 | 14 | @Override 15 | protected ClientsPage createPage(List items) { 16 | return new ClientsPage(items); 17 | } 18 | 19 | @Override 20 | protected ClientsPage createPage(Integer start, Integer length, Integer total, Integer limit, List items) { 21 | return new ClientsPage(start, length, total, limit, items); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/com/auth0/net/EmptyBodyRequest.java: -------------------------------------------------------------------------------- 1 | package com.auth0.net; 2 | 3 | import com.auth0.exception.Auth0Exception; 4 | import com.fasterxml.jackson.core.type.TypeReference; 5 | import okhttp3.OkHttpClient; 6 | import okhttp3.RequestBody; 7 | 8 | public class EmptyBodyRequest extends CustomRequest { 9 | 10 | public EmptyBodyRequest(OkHttpClient client, String url, String method, TypeReference tType) { 11 | super(client, url, method, tType); 12 | } 13 | 14 | @Override 15 | protected RequestBody createBody() throws Auth0Exception { 16 | return RequestBody.create(null, new byte[0]); 17 | } 18 | 19 | @Override 20 | public EmptyBodyRequest addParameter(String name, Object value) { 21 | //do nothing 22 | return this; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/com/auth0/json/mgmt/userblocks/BlockDetails.java: -------------------------------------------------------------------------------- 1 | package com.auth0.json.mgmt.userblocks; 2 | 3 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 4 | import com.fasterxml.jackson.annotation.JsonInclude; 5 | import com.fasterxml.jackson.annotation.JsonProperty; 6 | 7 | @SuppressWarnings({"unused", "WeakerAccess"}) 8 | @JsonIgnoreProperties(ignoreUnknown = true) 9 | @JsonInclude(JsonInclude.Include.NON_NULL) 10 | public class BlockDetails { 11 | 12 | @JsonProperty("identifier") 13 | private String identifier; 14 | @JsonProperty("ip") 15 | private String ip; 16 | 17 | @JsonProperty("identifier") 18 | public String getIdentifier() { 19 | return identifier; 20 | } 21 | 22 | @JsonProperty("ip") 23 | public String getIP() { 24 | return ip; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/test/resources/mgmt/event_logs_paged_list.json: -------------------------------------------------------------------------------- 1 | { 2 | "start": 0, 3 | "length": 14, 4 | "total": 14, 5 | "limit": 50, 6 | "logs": [ 7 | { 8 | "date": "2016-02-23T19:57:29.532Z", 9 | "type": "sapi", 10 | "client_id": "AaiyAPdpYdesoKnqjj8HJqRn4T5titww", 11 | "client_name": "My Game", 12 | "ip": "190.257.209.19", 13 | "location_info": {}, 14 | "details": {}, 15 | "user_id": "auth0|56c75c4e42b6359e98374bc2" 16 | }, 17 | { 18 | "date": "2016-03-23T19:57:31.532Z", 19 | "type": "lapi", 20 | "client_id": "AaiyAPdpYdesoKnqjj8HJqRn4T5titww", 21 | "client_name": "My Application", 22 | "ip": "190.257.209.29", 23 | "location_info": {}, 24 | "details": {}, 25 | "user_id": "auth0|56c75c4e42b6359e98374bc2" 26 | } 27 | ] 28 | } -------------------------------------------------------------------------------- /src/main/java/com/auth0/json/mgmt/logevents/LogEventsPageDeserializer.java: -------------------------------------------------------------------------------- 1 | package com.auth0.json.mgmt.logevents; 2 | 3 | import com.auth0.json.mgmt.PageDeserializer; 4 | 5 | import java.util.List; 6 | 7 | @SuppressWarnings({"unused", "WeakerAccess"}) 8 | class LogEventsPageDeserializer extends PageDeserializer { 9 | 10 | protected LogEventsPageDeserializer() { 11 | super(LogEvent.class, "logs"); 12 | } 13 | 14 | @Override 15 | protected LogEventsPage createPage(List items) { 16 | return new LogEventsPage(items); 17 | } 18 | 19 | @Override 20 | protected LogEventsPage createPage(Integer start, Integer length, Integer total, Integer limit, List items) { 21 | return new LogEventsPage(start, length, total, limit, items); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/com/auth0/json/mgmt/ResourceServersPageDeserializer.java: -------------------------------------------------------------------------------- 1 | package com.auth0.json.mgmt; 2 | 3 | import java.util.List; 4 | 5 | @SuppressWarnings({"unused", "WeakerAccess"}) 6 | class ResourceServersPageDeserializer extends PageDeserializer { 7 | 8 | ResourceServersPageDeserializer() { 9 | super(ResourceServer.class, "resource_servers"); 10 | } 11 | 12 | @Override 13 | protected ResourceServersPage createPage(List items) { 14 | return new ResourceServersPage(items); 15 | } 16 | 17 | @Override 18 | protected ResourceServersPage createPage(Integer start, Integer length, Integer total, Integer limit, List items) { 19 | return new ResourceServersPage(start, length, total, limit, items); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /src/test/java/com/auth0/client/mgmt/BaseMgmtEntityTest.java: -------------------------------------------------------------------------------- 1 | package com.auth0.client.mgmt; 2 | 3 | import com.auth0.client.MockServer; 4 | import org.junit.After; 5 | import org.junit.Before; 6 | import org.junit.Rule; 7 | import org.junit.rules.ExpectedException; 8 | 9 | public class BaseMgmtEntityTest { 10 | 11 | private static final String API_TOKEN = "apiToken"; 12 | 13 | protected MockServer server; 14 | protected ManagementAPI api; 15 | @Rule 16 | public ExpectedException exception = ExpectedException.none(); 17 | 18 | @Before 19 | public void setUp() throws Exception { 20 | server = new MockServer(); 21 | api = new ManagementAPI(server.getBaseUrl(), API_TOKEN); 22 | } 23 | 24 | @After 25 | public void tearDown() throws Exception { 26 | server.stop(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/test/java/com/auth0/json/mgmt/userblocks/BlockDetailsTest.java: -------------------------------------------------------------------------------- 1 | package com.auth0.json.mgmt.userblocks; 2 | 3 | import com.auth0.json.JsonTest; 4 | import org.junit.Test; 5 | 6 | import static org.hamcrest.MatcherAssert.assertThat; 7 | import static org.hamcrest.Matchers.is; 8 | import static org.hamcrest.Matchers.notNullValue; 9 | 10 | public class BlockDetailsTest extends JsonTest { 11 | 12 | private static final String json = "{\"ip\":\"10.0.0.1\", \"identifier\":\"username\"}"; 13 | 14 | @Test 15 | public void shouldDeserialize() throws Exception { 16 | BlockDetails details = fromJSON(json, BlockDetails.class); 17 | 18 | assertThat(details, is(notNullValue())); 19 | assertThat(details.getIdentifier(), is("username")); 20 | assertThat(details.getIP(), is("10.0.0.1")); 21 | } 22 | } -------------------------------------------------------------------------------- /src/test/java/com/auth0/json/mgmt/DailyStatsTest.java: -------------------------------------------------------------------------------- 1 | package com.auth0.json.mgmt; 2 | 3 | import com.auth0.json.JsonTest; 4 | import org.junit.Test; 5 | 6 | import static org.hamcrest.MatcherAssert.assertThat; 7 | import static org.hamcrest.Matchers.equalTo; 8 | import static org.hamcrest.Matchers.is; 9 | import static org.hamcrest.Matchers.notNullValue; 10 | 11 | public class DailyStatsTest extends JsonTest { 12 | private static final String json = "{\"logins\":123,\"date\":\"2017-01-18T17:45:08.328Z\"}"; 13 | 14 | @Test 15 | public void shouldDeserialize() throws Exception { 16 | DailyStats stats = fromJSON(json, DailyStats.class); 17 | 18 | assertThat(stats, is(notNullValue())); 19 | assertThat(stats.getDate(), is(equalTo(parseJSONDate("2017-01-18T17:45:08.328Z")))); 20 | assertThat(stats.getLogins(), is(123)); 21 | } 22 | 23 | } -------------------------------------------------------------------------------- /src/test/resources/mgmt/tenant.json: -------------------------------------------------------------------------------- 1 | { 2 | "change_password": { 3 | "enabled": false, 4 | "html": "" 5 | }, 6 | "guardian_mfa_page": { 7 | "enabled": false, 8 | "html": "" 9 | }, 10 | "default_audience": "", 11 | "default_directory": "", 12 | "error_page": { 13 | "html": "", 14 | "show_log_link": false, 15 | "url": "https://mycompany.org/error" 16 | }, 17 | "flags": { 18 | "change_pwd_flow_v1": false, 19 | "enable_client_connections": false, 20 | "enable_apis_section": false, 21 | "enable_pipeline2": false, 22 | "enable_dynamic_client_registration": false 23 | }, 24 | "friendly_name": "My Company", 25 | "picture_url": "https://mycompany.org/logo.png", 26 | "support_email": "support@mycompany.org", 27 | "support_url": "https://mycompany.org/support", 28 | "allowed_logout_urls": [ 29 | "https://mycompany.org/logoutCallback" 30 | ] 31 | } -------------------------------------------------------------------------------- /src/main/java/com/auth0/json/mgmt/client/Addon.java: -------------------------------------------------------------------------------- 1 | package com.auth0.json.mgmt.client; 2 | 3 | import com.fasterxml.jackson.annotation.*; 4 | 5 | import java.util.HashMap; 6 | import java.util.Map; 7 | 8 | @SuppressWarnings("WeakerAccess") 9 | @JsonIgnoreProperties(ignoreUnknown = true) 10 | @JsonInclude(JsonInclude.Include.NON_NULL) 11 | public class Addon { 12 | 13 | @JsonUnwrapped 14 | @JsonIgnore 15 | private Map properties; 16 | 17 | public Addon() { 18 | this.properties = new HashMap<>(); 19 | } 20 | 21 | @JsonAnySetter 22 | public void setProperty(String name, Object value) { 23 | properties.put(name, value); 24 | } 25 | 26 | @JsonAnyGetter 27 | public Map getProperties() { 28 | return properties; 29 | } 30 | 31 | public Object getProperty(String name) { 32 | return properties.get(name); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/com/auth0/json/mgmt/RulesPage.java: -------------------------------------------------------------------------------- 1 | package com.auth0.json.mgmt; 2 | 3 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 4 | import com.fasterxml.jackson.annotation.JsonInclude; 5 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 6 | 7 | import java.util.List; 8 | 9 | /** 10 | * Class that represents a given page of Rules. Related to the {@link com.auth0.client.mgmt.RulesEntity} entity. 11 | */ 12 | @SuppressWarnings({"unused", "WeakerAccess"}) 13 | @JsonIgnoreProperties(ignoreUnknown = true) 14 | @JsonInclude(JsonInclude.Include.NON_NULL) 15 | @JsonDeserialize(using = RulesPageDeserializer.class) 16 | public class RulesPage extends Page { 17 | 18 | public RulesPage(List items) { 19 | super(items); 20 | } 21 | 22 | public RulesPage(Integer start, Integer length, Integer total, Integer limit, List items) { 23 | super(start, length, total, limit, items); 24 | } 25 | 26 | } -------------------------------------------------------------------------------- /src/main/java/com/auth0/net/TokenRequest.java: -------------------------------------------------------------------------------- 1 | package com.auth0.net; 2 | 3 | import com.auth0.json.auth.TokenHolder; 4 | import com.fasterxml.jackson.core.type.TypeReference; 5 | import okhttp3.OkHttpClient; 6 | 7 | public class TokenRequest extends CustomRequest implements AuthRequest { 8 | 9 | public TokenRequest(OkHttpClient client, String url) { 10 | super(client, url, "POST", new TypeReference() { 11 | }); 12 | } 13 | 14 | @Override 15 | public TokenRequest setRealm(String realm) { 16 | super.addParameter("realm", realm); 17 | return this; 18 | } 19 | 20 | @Override 21 | public TokenRequest setAudience(String audience) { 22 | super.addParameter("audience", audience); 23 | return this; 24 | } 25 | 26 | @Override 27 | public TokenRequest setScope(String scope) { 28 | super.addParameter("scope", scope); 29 | return this; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/com/auth0/json/mgmt/GrantsPage.java: -------------------------------------------------------------------------------- 1 | package com.auth0.json.mgmt; 2 | 3 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 4 | import com.fasterxml.jackson.annotation.JsonInclude; 5 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 6 | 7 | import java.util.List; 8 | 9 | /** 10 | * Class that represents a given page of Grants. Related to the {@link com.auth0.client.mgmt.GrantsEntity} entity. 11 | */ 12 | @SuppressWarnings({"unused", "WeakerAccess"}) 13 | @JsonIgnoreProperties(ignoreUnknown = true) 14 | @JsonInclude(JsonInclude.Include.NON_NULL) 15 | @JsonDeserialize(using = GrantsPageDeserializer.class) 16 | public class GrantsPage extends Page { 17 | 18 | public GrantsPage(List items) { 19 | super(items); 20 | } 21 | 22 | public GrantsPage(Integer start, Integer length, Integer total, Integer limit, List items) { 23 | super(start, length, total, limit, items); 24 | } 25 | 26 | } -------------------------------------------------------------------------------- /.circleci/config.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | jobs: 3 | build: 4 | docker: 5 | - image: openjdk:8-jdk 6 | steps: 7 | - checkout 8 | - run: chmod +x gradlew 9 | # Download and cache dependencies 10 | - restore_cache: 11 | keys: 12 | - v1-dependencies-{{ checksum "build.gradle" }} 13 | # fallback to using the latest cache if no exact match is found 14 | - v1-dependencies- 15 | # run tests! 16 | - run: ./gradlew clean check jacocoTestReport --continue --console=plain 17 | - run: 18 | name: Upload Coverage 19 | when: on_success 20 | command: bash <(curl -s https://codecov.io/bash) 21 | - save_cache: 22 | paths: 23 | - ~/.m2 24 | key: v1-dependencies-{{ checksum "build.gradle" }} 25 | environment: 26 | GRADLE_OPTS: '-Dorg.gradle.jvmargs="-Xmx2048m -XX:+HeapDumpOnOutOfMemoryError"' 27 | _JAVA_OPTIONS: "-Xms512m -Xmx1024m" 28 | TERM: dumb -------------------------------------------------------------------------------- /src/main/java/com/auth0/json/mgmt/userblocks/UserBlocks.java: -------------------------------------------------------------------------------- 1 | package com.auth0.json.mgmt.userblocks; 2 | 3 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 4 | import com.fasterxml.jackson.annotation.JsonInclude; 5 | import com.fasterxml.jackson.annotation.JsonProperty; 6 | 7 | import java.util.List; 8 | 9 | /** 10 | * Class that represents an Auth0 User Block object. Related to the {@link com.auth0.client.mgmt.UserBlocksEntity} entity. 11 | */ 12 | @SuppressWarnings({"unused", "WeakerAccess"}) 13 | @JsonIgnoreProperties(ignoreUnknown = true) 14 | @JsonInclude(JsonInclude.Include.NON_NULL) 15 | public class UserBlocks { 16 | 17 | @JsonProperty("blocked_for") 18 | private List blockedFor; 19 | 20 | /** 21 | * Getter for the list of user block details. 22 | * 23 | * @return the list of block details. 24 | */ 25 | @JsonProperty("blocked_for") 26 | public List getBlockedFor() { 27 | return blockedFor; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/auth0/json/mgmt/users/UsersPage.java: -------------------------------------------------------------------------------- 1 | package com.auth0.json.mgmt.users; 2 | 3 | import com.auth0.json.mgmt.Page; 4 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 5 | import com.fasterxml.jackson.annotation.JsonInclude; 6 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 7 | 8 | import java.util.List; 9 | 10 | /** 11 | * Class that represents a given Ppge of Users. Related to the {@link com.auth0.client.mgmt.UsersEntity} entity. 12 | */ 13 | @SuppressWarnings({"unused", "WeakerAccess"}) 14 | @JsonIgnoreProperties(ignoreUnknown = true) 15 | @JsonInclude(JsonInclude.Include.NON_NULL) 16 | @JsonDeserialize(using = UsersPageDeserializer.class) 17 | public class UsersPage extends Page { 18 | 19 | public UsersPage(List items) { 20 | super(items); 21 | } 22 | 23 | public UsersPage(Integer start, Integer length, Integer total, Integer limit, List items) { 24 | super(start, length, total, limit, items); 25 | } 26 | 27 | } -------------------------------------------------------------------------------- /src/main/java/com/auth0/json/mgmt/ConnectionsPage.java: -------------------------------------------------------------------------------- 1 | package com.auth0.json.mgmt; 2 | 3 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 4 | import com.fasterxml.jackson.annotation.JsonInclude; 5 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 6 | 7 | import java.util.List; 8 | 9 | /** 10 | * Class that represents a given page of Grants. Related to the {@link com.auth0.client.mgmt.ConnectionsEntity} entity. 11 | */ 12 | @SuppressWarnings({"unused", "WeakerAccess"}) 13 | @JsonIgnoreProperties(ignoreUnknown = true) 14 | @JsonInclude(JsonInclude.Include.NON_NULL) 15 | @JsonDeserialize(using = ConnectionsPageDeserializer.class) 16 | public class ConnectionsPage extends Page { 17 | 18 | public ConnectionsPage(List items) { 19 | super(items); 20 | } 21 | 22 | public ConnectionsPage(Integer start, Integer length, Integer total, Integer limit, List items) { 23 | super(start, length, total, limit, items); 24 | } 25 | 26 | } -------------------------------------------------------------------------------- /src/main/java/com/auth0/net/AuthRequest.java: -------------------------------------------------------------------------------- 1 | package com.auth0.net; 2 | 3 | import com.auth0.json.auth.TokenHolder; 4 | 5 | /** 6 | * Class that represents an OAuth 2.0 Authentication/Authorization request. The execution will return a {@link TokenHolder}. 7 | */ 8 | public interface AuthRequest extends Request { 9 | 10 | /** 11 | * Setter for the realm value to request 12 | * 13 | * @param realm the realm to request 14 | * @return this request instance. 15 | */ 16 | AuthRequest setRealm(String realm); 17 | 18 | /** 19 | * Setter for the audience value to request 20 | * 21 | * @param audience the audience to request 22 | * @return this request instance. 23 | */ 24 | AuthRequest setAudience(String audience); 25 | 26 | /** 27 | * Setter for the scope value to request 28 | * 29 | * @param scope the scope to request 30 | * @return this request instance. 31 | */ 32 | AuthRequest setScope(String scope); 33 | } 34 | -------------------------------------------------------------------------------- /src/test/java/com/auth0/json/mgmt/jobs/JobTest.java: -------------------------------------------------------------------------------- 1 | package com.auth0.json.mgmt.jobs; 2 | 3 | import com.auth0.json.JsonTest; 4 | import org.junit.Test; 5 | 6 | import static org.hamcrest.Matchers.notNullValue; 7 | import static org.hamcrest.core.Is.is; 8 | import static org.junit.Assert.assertThat; 9 | 10 | public class JobTest extends JsonTest { 11 | 12 | private static final String json = "{\"status\": \"completed\",\"type\": \"verification_email\",\"created_at\": \"2016-02-23T19:57:29.532Z\",\"id\": \"job_0000000000000001\"}"; 13 | 14 | @Test 15 | public void shouldDeserialize() throws Exception { 16 | Job job = fromJSON(json, Job.class); 17 | 18 | assertThat(job, is(notNullValue())); 19 | assertThat(job.getId(), is("job_0000000000000001")); 20 | assertThat(job.getStatus(), is("completed")); 21 | assertThat(job.getType(), is("verification_email")); 22 | assertThat(job.getCreatedAt(), is(parseJSONDate("2016-02-23T19:57:29.532Z"))); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/com/auth0/json/mgmt/ClientGrantsPage.java: -------------------------------------------------------------------------------- 1 | package com.auth0.json.mgmt; 2 | 3 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 4 | import com.fasterxml.jackson.annotation.JsonInclude; 5 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 6 | 7 | import java.util.List; 8 | 9 | /** 10 | * Class that represents a given page of Client Grants. Related to the {@link com.auth0.client.mgmt.ClientGrantsEntity} entity. 11 | */ 12 | @SuppressWarnings({"unused", "WeakerAccess"}) 13 | @JsonIgnoreProperties(ignoreUnknown = true) 14 | @JsonInclude(JsonInclude.Include.NON_NULL) 15 | @JsonDeserialize(using = ClientGrantsPageDeserializer.class) 16 | public class ClientGrantsPage extends Page { 17 | 18 | public ClientGrantsPage(List items) { 19 | super(items); 20 | } 21 | 22 | public ClientGrantsPage(Integer start, Integer length, Integer total, Integer limit, List items) { 23 | super(start, length, total, limit, items); 24 | } 25 | 26 | } -------------------------------------------------------------------------------- /src/main/java/com/auth0/json/mgmt/client/ClientsPage.java: -------------------------------------------------------------------------------- 1 | package com.auth0.json.mgmt.client; 2 | 3 | import com.auth0.json.mgmt.Page; 4 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 5 | import com.fasterxml.jackson.annotation.JsonInclude; 6 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 7 | 8 | import java.util.List; 9 | 10 | /** 11 | * Class that represents a given page of Clients. Related to the {@link com.auth0.client.mgmt.ClientsEntity} entity. 12 | */ 13 | @SuppressWarnings({"unused", "WeakerAccess"}) 14 | @JsonIgnoreProperties(ignoreUnknown = true) 15 | @JsonInclude(JsonInclude.Include.NON_NULL) 16 | @JsonDeserialize(using = ClientsPageDeserializer.class) 17 | public class ClientsPage extends Page { 18 | 19 | public ClientsPage(List items) { 20 | super(items); 21 | } 22 | 23 | public ClientsPage(Integer start, Integer length, Integer total, Integer limit, List items) { 24 | super(start, length, total, limit, items); 25 | } 26 | 27 | } -------------------------------------------------------------------------------- /src/main/java/com/auth0/json/mgmt/logevents/LogEventsPage.java: -------------------------------------------------------------------------------- 1 | package com.auth0.json.mgmt.logevents; 2 | 3 | import com.auth0.json.mgmt.Page; 4 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 5 | import com.fasterxml.jackson.annotation.JsonInclude; 6 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 7 | 8 | import java.util.List; 9 | 10 | /** 11 | * Class that represents a given page of Log Events. Related to the {@link com.auth0.client.mgmt.LogEventsEntity} entity. 12 | */ 13 | @SuppressWarnings({"unused", "WeakerAccess"}) 14 | @JsonIgnoreProperties(ignoreUnknown = true) 15 | @JsonInclude(JsonInclude.Include.NON_NULL) 16 | @JsonDeserialize(using = LogEventsPageDeserializer.class) 17 | public class LogEventsPage extends Page { 18 | 19 | public LogEventsPage(List items) { 20 | super(items); 21 | } 22 | 23 | public LogEventsPage(Integer start, Integer length, Integer total, Integer limit, List items) { 24 | super(start, length, total, limit, items); 25 | } 26 | 27 | } -------------------------------------------------------------------------------- /src/main/java/com/auth0/json/mgmt/ResourceServersPage.java: -------------------------------------------------------------------------------- 1 | package com.auth0.json.mgmt; 2 | 3 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 4 | import com.fasterxml.jackson.annotation.JsonInclude; 5 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 6 | 7 | import java.util.List; 8 | 9 | /** 10 | * Class that represents a given page of Resource Servers. Related to the {@link com.auth0.client.mgmt.ResourceServerEntity} entity. 11 | */ 12 | @SuppressWarnings({"unused", "WeakerAccess"}) 13 | @JsonIgnoreProperties(ignoreUnknown = true) 14 | @JsonInclude(JsonInclude.Include.NON_NULL) 15 | @JsonDeserialize(using = ResourceServersPageDeserializer.class) 16 | public class ResourceServersPage extends Page { 17 | 18 | public ResourceServersPage(List items) { 19 | super(items); 20 | } 21 | 22 | public ResourceServersPage(Integer start, Integer length, Integer total, Integer limit, List items) { 23 | super(start, length, total, limit, items); 24 | } 25 | 26 | } -------------------------------------------------------------------------------- /src/test/java/com/auth0/json/auth/TokenHolderTest.java: -------------------------------------------------------------------------------- 1 | package com.auth0.json.auth; 2 | 3 | import com.auth0.json.JsonTest; 4 | import org.junit.Test; 5 | 6 | import static org.hamcrest.MatcherAssert.assertThat; 7 | import static org.hamcrest.Matchers.is; 8 | import static org.hamcrest.Matchers.notNullValue; 9 | 10 | public class TokenHolderTest extends JsonTest { 11 | 12 | private static final String json = "{\"id_token\":\"eyJ0eXAiOiJKV1Qi...\",\"access_token\":\"A9CvPwFojaBI...\",\"refresh_token\":\"GEbRxBN...edjnXbL\",\"token_type\": \"bearer\",\"expires_in\":86000}"; 13 | 14 | @Test 15 | public void shouldDeserialize() throws Exception { 16 | TokenHolder holder = fromJSON(json, TokenHolder.class); 17 | 18 | assertThat(holder, is(notNullValue())); 19 | 20 | assertThat(holder.getAccessToken(), is(notNullValue())); 21 | assertThat(holder.getIdToken(), is(notNullValue())); 22 | assertThat(holder.getRefreshToken(), is(notNullValue())); 23 | assertThat(holder.getTokenType(), is(notNullValue())); 24 | assertThat(holder.getExpiresIn(), is(notNullValue())); 25 | } 26 | } -------------------------------------------------------------------------------- /src/test/java/com/auth0/json/mgmt/ScopeTest.java: -------------------------------------------------------------------------------- 1 | package com.auth0.json.mgmt; 2 | 3 | import com.auth0.json.JsonMatcher; 4 | import com.auth0.json.JsonTest; 5 | import org.junit.Test; 6 | 7 | import static org.hamcrest.Matchers.is; 8 | import static org.junit.Assert.assertThat; 9 | 10 | public class ScopeTest extends JsonTest { 11 | private static final String SCOPE_JSON = "src/test/resources/mgmt/scope.json"; 12 | 13 | @Test 14 | public void serialize() throws Exception { 15 | Scope scope = new Scope("read:client_grants"); 16 | scope.setDescription("Read Client Grants"); 17 | String json = toJSON(scope); 18 | 19 | assertThat(json, JsonMatcher.hasEntry("value", "read:client_grants")); 20 | assertThat(json, JsonMatcher.hasEntry("description", "Read Client Grants")); 21 | } 22 | 23 | @Test 24 | public void deserialize() throws Exception { 25 | Scope deserialized = fromJSON(readTextFile(SCOPE_JSON), Scope.class); 26 | 27 | assertThat(deserialized.getValue(), is("read:client_grants")); 28 | assertThat(deserialized.getDescription(), is("Read Client Grants")); 29 | } 30 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2018 Auth0, Inc. (http://auth0.com) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /src/main/java/com/auth0/client/mgmt/filter/ResourceServersFilter.java: -------------------------------------------------------------------------------- 1 | package com.auth0.client.mgmt.filter; 2 | 3 | /** 4 | * Class used to filter the results received when calling the Resource Servers endpoint. Related to the {@link com.auth0.client.mgmt.ResourceServerEntity} entity. 5 | */ 6 | public class ResourceServersFilter extends BaseFilter { 7 | 8 | /** 9 | * Filter by page 10 | * 11 | * @param pageNumber the page number to retrieve. 12 | * @param amountPerPage the amount of items per page to retrieve. 13 | * @return this filter instance 14 | */ 15 | public ResourceServersFilter withPage(int pageNumber, int amountPerPage) { 16 | parameters.put("page", pageNumber); 17 | parameters.put("per_page", amountPerPage); 18 | return this; 19 | } 20 | 21 | /** 22 | * Include the query summary 23 | * 24 | * @param includeTotals whether to include or not the query summary. 25 | * @return this filter instance 26 | */ 27 | public ResourceServersFilter withTotals(boolean includeTotals) { 28 | parameters.put("include_totals", includeTotals); 29 | return this; 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/test/java/com/auth0/json/mgmt/TokenTest.java: -------------------------------------------------------------------------------- 1 | package com.auth0.json.mgmt; 2 | 3 | import com.auth0.json.JsonMatcher; 4 | import com.auth0.json.JsonTest; 5 | import org.junit.Test; 6 | 7 | import static org.hamcrest.MatcherAssert.assertThat; 8 | import static org.hamcrest.Matchers.is; 9 | import static org.hamcrest.Matchers.notNullValue; 10 | 11 | public class TokenTest extends JsonTest { 12 | private static final String json = "{\"jti\":\"id\",\"aud\":\"myapi\"}"; 13 | 14 | @Test 15 | public void shouldSerialize() throws Exception { 16 | Token token = new Token("id"); 17 | token.setAud("myapi"); 18 | 19 | String serialized = toJSON(token); 20 | assertThat(serialized, is(notNullValue())); 21 | assertThat(serialized, JsonMatcher.hasEntry("jti", "id")); 22 | assertThat(serialized, JsonMatcher.hasEntry("aud", "myapi")); 23 | } 24 | 25 | @Test 26 | public void shouldDeserialize() throws Exception { 27 | Token token = fromJSON(json, Token.class); 28 | 29 | assertThat(token, is(notNullValue())); 30 | assertThat(token.getAud(), is("myapi")); 31 | assertThat(token.getJTI(), is("id")); 32 | } 33 | 34 | } -------------------------------------------------------------------------------- /src/test/java/com/auth0/net/TelemetryTest.java: -------------------------------------------------------------------------------- 1 | package com.auth0.net; 2 | 3 | import org.junit.Before; 4 | import org.junit.Test; 5 | 6 | import static org.hamcrest.Matchers.*; 7 | import static org.junit.Assert.assertThat; 8 | 9 | public class TelemetryTest { 10 | 11 | private Telemetry telemetry; 12 | 13 | @Before 14 | public void setUp() throws Exception { 15 | telemetry = new Telemetry("auth0-java", "1.0.0"); 16 | } 17 | 18 | @Test 19 | public void shouldReturnBase64() throws Exception { 20 | assertThat(telemetry.getValue(), is(notNullValue())); 21 | assertThat(telemetry.getValue(), is("eyJuYW1lIjoiYXV0aDAtamF2YSIsInZlcnNpb24iOiIxLjAuMCJ9")); 22 | } 23 | 24 | @Test 25 | public void shouldReturnNullWhenNoInfoIsProvided() throws Exception { 26 | telemetry = new Telemetry(null, null); 27 | assertThat(telemetry.getValue(), is(nullValue())); 28 | } 29 | 30 | @Test 31 | public void shouldGetName() throws Exception { 32 | assertThat(telemetry.getName(), is("auth0-java")); 33 | } 34 | 35 | @Test 36 | public void shouldGetVersion() throws Exception { 37 | assertThat(telemetry.getVersion(), is("1.0.0")); 38 | } 39 | } -------------------------------------------------------------------------------- /src/test/java/com/auth0/json/mgmt/guardian/FactorTest.java: -------------------------------------------------------------------------------- 1 | package com.auth0.json.mgmt.guardian; 2 | 3 | import com.auth0.json.JsonMatcher; 4 | import com.auth0.json.JsonTest; 5 | import org.junit.Test; 6 | 7 | import static org.hamcrest.MatcherAssert.assertThat; 8 | import static org.hamcrest.Matchers.is; 9 | import static org.hamcrest.Matchers.notNullValue; 10 | 11 | public class FactorTest extends JsonTest { 12 | 13 | private static final String readOnlyJson = "{\"enabled\":true,\"name\":\"sms\",\"trial_expired\":true}"; 14 | 15 | @Test 16 | public void shouldSerialize() throws Exception { 17 | Factor factor = new Factor(true); 18 | 19 | String serialized = toJSON(factor); 20 | assertThat(serialized, is(notNullValue())); 21 | assertThat(serialized, JsonMatcher.hasEntry("enabled", true)); 22 | } 23 | 24 | @Test 25 | public void shouldDeserialize() throws Exception { 26 | Factor factor = fromJSON(readOnlyJson, Factor.class); 27 | 28 | assertThat(factor, is(notNullValue())); 29 | assertThat(factor.isEnabled(), is(true)); 30 | assertThat(factor.getName(), is("sms")); 31 | assertThat(factor.isTrialExpired(), is(true)); 32 | } 33 | } -------------------------------------------------------------------------------- /src/main/java/com/auth0/net/BaseRequest.java: -------------------------------------------------------------------------------- 1 | package com.auth0.net; 2 | 3 | import com.auth0.exception.Auth0Exception; 4 | import okhttp3.OkHttpClient; 5 | import okhttp3.Response; 6 | 7 | import java.io.IOException; 8 | 9 | public abstract class BaseRequest implements Request { 10 | 11 | private final OkHttpClient client; 12 | 13 | BaseRequest(OkHttpClient client) { 14 | this.client = client; 15 | } 16 | 17 | protected abstract okhttp3.Request createRequest() throws Auth0Exception; 18 | 19 | protected abstract T parseResponse(Response response) throws Auth0Exception; 20 | 21 | /** 22 | * Executes this request. 23 | * 24 | * @return the response body JSON decoded as T 25 | * @throws Auth0Exception if the request execution fails. 26 | */ 27 | @Override 28 | public T execute() throws Auth0Exception { 29 | okhttp3.Request request = createRequest(); 30 | Response response; 31 | try { 32 | response = client.newCall(request).execute(); 33 | } catch (IOException e) { 34 | throw new Auth0Exception("Failed to execute request", e); 35 | } 36 | 37 | return parseResponse(response); 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/com/auth0/net/TelemetryInterceptor.java: -------------------------------------------------------------------------------- 1 | package com.auth0.net; 2 | 3 | import com.auth0.BuildConfig; 4 | import okhttp3.Interceptor; 5 | import okhttp3.Response; 6 | 7 | import java.io.IOException; 8 | 9 | public class TelemetryInterceptor implements Interceptor { 10 | 11 | private Telemetry telemetry; 12 | private boolean enabled; 13 | 14 | public TelemetryInterceptor() { 15 | this(new Telemetry(BuildConfig.NAME, BuildConfig.VERSION)); 16 | } 17 | 18 | TelemetryInterceptor(Telemetry telemetry) { 19 | this.telemetry = telemetry; 20 | this.enabled = true; 21 | } 22 | 23 | @Override 24 | public Response intercept(Chain chain) throws IOException { 25 | if (!enabled) { 26 | return chain.proceed(chain.request()); 27 | } 28 | 29 | okhttp3.Request request = chain.request() 30 | .newBuilder() 31 | .addHeader(Telemetry.HEADER_NAME, telemetry.getValue()) 32 | .build(); 33 | return chain.proceed(request); 34 | } 35 | 36 | public void setEnabled(boolean enabled) { 37 | this.enabled = enabled; 38 | } 39 | 40 | public boolean isEnabled() { 41 | return enabled; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/test/java/com/auth0/json/mgmt/client/IOSTest.java: -------------------------------------------------------------------------------- 1 | package com.auth0.json.mgmt.client; 2 | 3 | import com.auth0.json.JsonMatcher; 4 | import com.auth0.json.JsonTest; 5 | import org.junit.Test; 6 | 7 | import static org.hamcrest.MatcherAssert.assertThat; 8 | import static org.hamcrest.Matchers.is; 9 | import static org.hamcrest.Matchers.notNullValue; 10 | 11 | public class IOSTest extends JsonTest { 12 | 13 | private static final String json = "{\"team_id\":\"team\",\"app_bundle_identifier\":\"identifier\"}"; 14 | 15 | @Test 16 | public void shouldSerialize() throws Exception { 17 | IOS ios = new IOS("team", "identifier"); 18 | 19 | String serialized = toJSON(ios); 20 | assertThat(serialized, is(notNullValue())); 21 | assertThat(serialized, JsonMatcher.hasEntry("team_id", "team")); 22 | assertThat(serialized, JsonMatcher.hasEntry("app_bundle_identifier", "identifier")); 23 | } 24 | 25 | @Test 26 | public void shouldDeserialize() throws Exception { 27 | IOS ios = fromJSON(json, IOS.class); 28 | 29 | assertThat(ios, is(notNullValue())); 30 | 31 | assertThat(ios.getTeamId(), is("team")); 32 | assertThat(ios.getAppBundleIdentifier(), is("identifier")); 33 | } 34 | } -------------------------------------------------------------------------------- /src/main/java/com/auth0/json/mgmt/Scope.java: -------------------------------------------------------------------------------- 1 | package com.auth0.json.mgmt; 2 | 3 | import com.fasterxml.jackson.annotation.JsonCreator; 4 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 5 | import com.fasterxml.jackson.annotation.JsonInclude; 6 | import com.fasterxml.jackson.annotation.JsonProperty; 7 | 8 | @SuppressWarnings({"WeakerAccess", "unused"}) 9 | @JsonIgnoreProperties(ignoreUnknown = true) 10 | @JsonInclude(JsonInclude.Include.NON_NULL) 11 | public class Scope { 12 | @JsonProperty("description") 13 | private String description; 14 | @JsonProperty("value") 15 | private String value; 16 | 17 | @JsonCreator 18 | public Scope(@JsonProperty("value") String value) { 19 | this.value = value; 20 | } 21 | 22 | @JsonProperty("description") 23 | public String getDescription() { 24 | return description; 25 | } 26 | 27 | @JsonProperty("description") 28 | public void setDescription(String description) { 29 | this.description = description; 30 | } 31 | 32 | @JsonProperty("value") 33 | public String getValue() { 34 | return value; 35 | } 36 | 37 | @JsonProperty("value") 38 | public void setValue(String value) { 39 | this.value = value; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/test/java/com/auth0/json/mgmt/users/IdentityTest.java: -------------------------------------------------------------------------------- 1 | package com.auth0.json.mgmt.users; 2 | 3 | import com.auth0.json.JsonTest; 4 | import org.junit.Test; 5 | 6 | import static org.hamcrest.MatcherAssert.assertThat; 7 | import static org.hamcrest.Matchers.*; 8 | 9 | public class IdentityTest extends JsonTest { 10 | 11 | private static final String json = "{\"connection\":\"auth0\",\"user_id\":\"user|123\",\"isSocial\":true,\"provider\":\"oauth\",\"access_token\":\"aTokEn\",\"profileData\":{},\"access_token_secret\":\"s3cr3t\"}"; 12 | 13 | @Test 14 | public void shouldDeserialize() throws Exception { 15 | Identity identity = fromJSON(json, Identity.class); 16 | 17 | assertThat(identity, is(notNullValue())); 18 | assertThat(identity.getConnection(), is("auth0")); 19 | assertThat(identity.getUserId(), is("user|123")); 20 | assertThat(identity.isSocial(), is(true)); 21 | assertThat(identity.getProvider(), is("oauth")); 22 | assertThat(identity.getAccessToken(), is("aTokEn")); 23 | assertThat(identity.getProfileData(), is(notNullValue())); 24 | assertThat(identity.getValues(), is(notNullValue())); 25 | assertThat(identity.getValues(), hasEntry("access_token_secret", (Object) "s3cr3t")); 26 | } 27 | } -------------------------------------------------------------------------------- /src/test/java/com/auth0/json/mgmt/client/MobileTest.java: -------------------------------------------------------------------------------- 1 | package com.auth0.json.mgmt.client; 2 | 3 | import com.auth0.json.JsonMatcher; 4 | import com.auth0.json.JsonTest; 5 | import org.junit.Test; 6 | 7 | import static org.hamcrest.MatcherAssert.assertThat; 8 | import static org.hamcrest.Matchers.is; 9 | import static org.hamcrest.Matchers.notNullValue; 10 | 11 | public class MobileTest extends JsonTest { 12 | 13 | private static final String json = "{\"android\":{},\"ios\":{}}"; 14 | 15 | @Test 16 | public void shouldSerialize() throws Exception { 17 | Android android = new Android(null, null); 18 | IOS ios = new IOS(null, null); 19 | Mobile mobile = new Mobile(android, ios); 20 | 21 | String serialized = toJSON(mobile); 22 | assertThat(serialized, is(notNullValue())); 23 | assertThat(serialized, JsonMatcher.hasEntry("android", notNullValue())); 24 | assertThat(serialized, JsonMatcher.hasEntry("ios", notNullValue())); 25 | } 26 | 27 | @Test 28 | public void shouldDeserialize() throws Exception { 29 | Mobile mobile = fromJSON(json, Mobile.class); 30 | 31 | assertThat(mobile, is(notNullValue())); 32 | assertThat(mobile.getAndroid(), is(notNullValue())); 33 | assertThat(mobile.getIOS(), is(notNullValue())); 34 | } 35 | } -------------------------------------------------------------------------------- /src/test/resources/mgmt/resource_servers_list.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "id": "23445566abab", 4 | "name": "Some API", 5 | "identifier": "https://api.my-company.com/api/v2/", 6 | "signing_alg": "RS256", 7 | "token_lifetime": 86400, 8 | "token_lifetime_for_web": 7200, 9 | "allow_offline_access": false, 10 | "skip_consent_for_verifiable_first_party_clients": false, 11 | "scopes": [ 12 | { 13 | "description": "Read Client Grants", 14 | "value": "read:client_grants" 15 | }, 16 | { 17 | "description": "Create Client Grants", 18 | "value": "create:client_grants" 19 | } 20 | ], 21 | "is_system": true 22 | }, 23 | { 24 | "id": "3223232da", 25 | "name": "Another API", 26 | "identifier": "https://another-api.my-company.com/api/v2/", 27 | "signing_alg": "RS256", 28 | "token_lifetime": 86400, 29 | "token_lifetime_for_web": 7200, 30 | "allow_offline_access": false, 31 | "skip_consent_for_verifiable_first_party_clients": false, 32 | "scopes": [ 33 | { 34 | "description": "Read Client Grants", 35 | "value": "read:client_grants" 36 | }, 37 | { 38 | "description": "Create Client Grants", 39 | "value": "create:client_grants" 40 | } 41 | ], 42 | "is_system": true 43 | } 44 | ] -------------------------------------------------------------------------------- /src/main/java/com/auth0/json/auth/UserInfo.java: -------------------------------------------------------------------------------- 1 | package com.auth0.json.auth; 2 | 3 | import com.fasterxml.jackson.annotation.JsonAnyGetter; 4 | import com.fasterxml.jackson.annotation.JsonAnySetter; 5 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 6 | import com.fasterxml.jackson.annotation.JsonInclude; 7 | 8 | import java.util.HashMap; 9 | import java.util.Map; 10 | 11 | /** 12 | * Class that holds the Information related to a User's Access Token. Obtained after a call to {@link com.auth0.client.auth.AuthAPI#userInfo(String)}, 13 | * {@link com.auth0.client.auth.AuthAPI#signUp(String, String, String)} or {@link com.auth0.client.auth.AuthAPI#signUp(String, String, String, String)}. 14 | */ 15 | @JsonIgnoreProperties(ignoreUnknown = true) 16 | @JsonInclude(JsonInclude.Include.NON_NULL) 17 | public class UserInfo { 18 | 19 | private Map values; 20 | 21 | UserInfo() { 22 | values = new HashMap<>(); 23 | } 24 | 25 | @JsonAnySetter 26 | void setValue(String key, Object value) { 27 | values.put(key, value); 28 | } 29 | 30 | /** 31 | * Getter for the values contained in this object 32 | * 33 | * @return the values contained in the object. 34 | */ 35 | @JsonAnyGetter 36 | public Map getValues() { 37 | return values; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/test/resources/mgmt/user.json: -------------------------------------------------------------------------------- 1 | { 2 | "email": "john.doe@gmail.com", 3 | "email_verified": false, 4 | "username": "johndoe", 5 | "phone_number": "+199999999999999", 6 | "phone_verified": false, 7 | "user_id": "usr_5457edea1b8f33391a000004", 8 | "created_at": "", 9 | "updated_at": "", 10 | "identities": [ 11 | { 12 | "provider": "facebook", 13 | "user_id": "5457edea1b8f2289", 14 | "connection": "facebook", 15 | "isSocial": true 16 | }, 17 | { 18 | "profileData": { 19 | "name": "Auth0️", 20 | "picture": "https://pbs.twimg.com/profile_images/auth0/5457ed_normal.jpg", 21 | "created_at": "Fri May 20 17:13:23 +0000 2011", 22 | "description": "My twitter bio", 23 | "lang": "es", 24 | "location": "Palermo, Buenos Aires.", 25 | "screen_name": "auth0", 26 | "time_zone": "Buenos Aires", 27 | "utc_offset": -10800 28 | }, 29 | "provider": "twitter", 30 | "user_id": "5457ed", 31 | "connection": "twitter", 32 | "isSocial": true 33 | } 34 | ], 35 | "app_metadata": {}, 36 | "user_metadata": {}, 37 | "picture": "", 38 | "name": "", 39 | "nickname": "", 40 | "multifactor": [], 41 | "last_ip": "", 42 | "last_login": "", 43 | "logins_count": 0, 44 | "blocked": false, 45 | "given_name": "", 46 | "family_name": "" 47 | } -------------------------------------------------------------------------------- /src/main/java/com/auth0/json/auth/CreatedUser.java: -------------------------------------------------------------------------------- 1 | package com.auth0.json.auth; 2 | 3 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 4 | import com.fasterxml.jackson.annotation.JsonInclude; 5 | import com.fasterxml.jackson.annotation.JsonProperty; 6 | 7 | /** 8 | * Class that holds the data of a newly created User. Obtained after a call to {@link com.auth0.client.auth.AuthAPI#signUp(String, String, String)} 9 | * or {@link com.auth0.client.auth.AuthAPI#signUp(String, String, String, String)}. 10 | */ 11 | @JsonIgnoreProperties(ignoreUnknown = true) 12 | @JsonInclude(JsonInclude.Include.NON_NULL) 13 | public class CreatedUser { 14 | 15 | @JsonProperty("_id") 16 | private String userId; 17 | @JsonProperty("email") 18 | private String email; 19 | @JsonProperty("username") 20 | private String username; 21 | @JsonProperty("email_verified") 22 | private Boolean emailVerified; 23 | 24 | @JsonProperty("_id") 25 | public String getUserId() { 26 | return userId; 27 | } 28 | 29 | @JsonProperty("email") 30 | public String getEmail() { 31 | return email; 32 | } 33 | 34 | @JsonProperty("username") 35 | public String getUsername() { 36 | return username; 37 | } 38 | 39 | @JsonProperty("email_verified") 40 | public Boolean isEmailVerified() { 41 | return emailVerified; 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/test/java/com/auth0/client/mgmt/filter/ResourceServersFilterTest.java: -------------------------------------------------------------------------------- 1 | package com.auth0.client.mgmt.filter; 2 | 3 | import org.hamcrest.Matchers; 4 | import org.junit.Before; 5 | import org.junit.Test; 6 | 7 | import static org.hamcrest.CoreMatchers.is; 8 | import static org.hamcrest.CoreMatchers.notNullValue; 9 | import static org.junit.Assert.assertThat; 10 | 11 | public class ResourceServersFilterTest { 12 | 13 | private ResourceServersFilter filter; 14 | 15 | @Before 16 | public void setUp() throws Exception { 17 | filter = new ResourceServersFilter(); 18 | } 19 | 20 | @Test 21 | public void shouldFilterByPage() throws Exception { 22 | ResourceServersFilter instance = filter.withPage(5, 10); 23 | 24 | assertThat(filter, is(instance)); 25 | assertThat(filter.getAsMap(), is(notNullValue())); 26 | assertThat(filter.getAsMap(), Matchers.hasEntry("per_page", (Object) 10)); 27 | assertThat(filter.getAsMap(), Matchers.hasEntry("page", (Object) 5)); 28 | } 29 | 30 | @Test 31 | public void shouldIncludeTotals() throws Exception { 32 | ResourceServersFilter instance = filter.withTotals(true); 33 | 34 | assertThat(filter, is(instance)); 35 | assertThat(filter.getAsMap(), is(notNullValue())); 36 | assertThat(filter.getAsMap(), Matchers.hasEntry("include_totals", (Object) true)); 37 | } 38 | } -------------------------------------------------------------------------------- /src/test/java/com/auth0/json/mgmt/client/SigningKeyTest.java: -------------------------------------------------------------------------------- 1 | package com.auth0.json.mgmt.client; 2 | 3 | import com.auth0.json.JsonMatcher; 4 | import com.auth0.json.JsonTest; 5 | import org.junit.Test; 6 | 7 | import static org.hamcrest.MatcherAssert.assertThat; 8 | import static org.hamcrest.Matchers.is; 9 | import static org.hamcrest.Matchers.notNullValue; 10 | 11 | public class SigningKeyTest extends JsonTest { 12 | 13 | private static final String json = "{\"cert\":\"cert\",\"pkcs7\":\"pkcs7\",\"subject\":\"subject\"}"; 14 | 15 | @Test 16 | public void shouldSerialize() throws Exception { 17 | SigningKey key = new SigningKey("cert", "pkcs7", "subject"); 18 | 19 | String serialized = toJSON(key); 20 | assertThat(serialized, is(notNullValue())); 21 | assertThat(serialized, JsonMatcher.hasEntry("cert", "cert")); 22 | assertThat(serialized, JsonMatcher.hasEntry("pkcs7", "pkcs7")); 23 | assertThat(serialized, JsonMatcher.hasEntry("subject", "subject")); 24 | } 25 | 26 | @Test 27 | public void shouldDeserialize() throws Exception { 28 | SigningKey key = fromJSON(json, SigningKey.class); 29 | 30 | assertThat(key, is(notNullValue())); 31 | assertThat(key.getCert(), is("cert")); 32 | assertThat(key.getPKCS7(), is("pkcs7")); 33 | assertThat(key.getSubject(), is("subject")); 34 | } 35 | } -------------------------------------------------------------------------------- /src/test/java/com/auth0/json/mgmt/guardian/GuardianTemplatesTest.java: -------------------------------------------------------------------------------- 1 | package com.auth0.json.mgmt.guardian; 2 | 3 | import com.auth0.json.JsonMatcher; 4 | import com.auth0.json.JsonTest; 5 | import org.junit.Test; 6 | 7 | import static org.hamcrest.MatcherAssert.assertThat; 8 | import static org.hamcrest.Matchers.is; 9 | import static org.hamcrest.Matchers.notNullValue; 10 | 11 | public class GuardianTemplatesTest extends JsonTest { 12 | private static final String json = "{\"enrollment_message\":\"enrollme\",\"verification_message\":\"verifyme\"}"; 13 | 14 | @Test 15 | public void shouldSerialize() throws Exception { 16 | GuardianTemplates templates = new GuardianTemplates("enrollme", "verifyme"); 17 | 18 | String serialized = toJSON(templates); 19 | assertThat(serialized, is(notNullValue())); 20 | assertThat(serialized, JsonMatcher.hasEntry("enrollment_message", "enrollme")); 21 | assertThat(serialized, JsonMatcher.hasEntry("verification_message", "verifyme")); 22 | } 23 | 24 | @Test 25 | public void shouldDeserialize() throws Exception { 26 | GuardianTemplates templates = fromJSON(json, GuardianTemplates.class); 27 | 28 | assertThat(templates, is(notNullValue())); 29 | assertThat(templates.getEnrollmentMessage(), is("enrollme")); 30 | assertThat(templates.getVerificationMessage(), is("verifyme")); 31 | } 32 | 33 | } -------------------------------------------------------------------------------- /src/test/java/com/auth0/json/mgmt/tenants/PageCustomizationTest.java: -------------------------------------------------------------------------------- 1 | package com.auth0.json.mgmt.tenants; 2 | 3 | import com.auth0.json.JsonMatcher; 4 | import com.auth0.json.JsonTest; 5 | import org.junit.Test; 6 | 7 | import static org.hamcrest.MatcherAssert.assertThat; 8 | import static org.hamcrest.Matchers.is; 9 | import static org.hamcrest.Matchers.notNullValue; 10 | 11 | public class PageCustomizationTest extends JsonTest { 12 | 13 | private static final String json = "{\"enabled\":true,\"html\":\"thewebpage\"}"; 14 | 15 | @Test 16 | public void shouldSerialize() throws Exception { 17 | PageCustomization customization = new PageCustomization(); 18 | customization.setEnabled(true); 19 | customization.setHTML("thewebpage"); 20 | 21 | String serialized = toJSON(customization); 22 | assertThat(serialized, is(notNullValue())); 23 | assertThat(serialized, JsonMatcher.hasEntry("enabled", true)); 24 | assertThat(serialized, JsonMatcher.hasEntry("html", "thewebpage")); 25 | } 26 | 27 | @Test 28 | public void shouldDeserialize() throws Exception { 29 | PageCustomization customization = fromJSON(json, PageCustomization.class); 30 | 31 | assertThat(customization, is(notNullValue())); 32 | assertThat(customization.isEnabled(), is(true)); 33 | assertThat(customization.getHTML(), is("thewebpage")); 34 | } 35 | 36 | } -------------------------------------------------------------------------------- /src/test/java/com/auth0/json/mgmt/client/EncryptionKeyTest.java: -------------------------------------------------------------------------------- 1 | package com.auth0.json.mgmt.client; 2 | 3 | import com.auth0.json.JsonMatcher; 4 | import com.auth0.json.JsonTest; 5 | import org.junit.Test; 6 | 7 | import static org.hamcrest.MatcherAssert.assertThat; 8 | import static org.hamcrest.Matchers.is; 9 | import static org.hamcrest.Matchers.notNullValue; 10 | 11 | public class EncryptionKeyTest extends JsonTest { 12 | 13 | private static final String json = "{\"pub\":\"pub\",\"cert\":\"cert\",\"subject\":\"subject\"}"; 14 | 15 | @Test 16 | public void shouldSerialize() throws Exception { 17 | EncryptionKey key = new EncryptionKey("pub", "cert"); 18 | key.setSubject("subject"); 19 | 20 | String serialized = toJSON(key); 21 | assertThat(serialized, is(notNullValue())); 22 | assertThat(serialized, JsonMatcher.hasEntry("pub", "pub")); 23 | assertThat(serialized, JsonMatcher.hasEntry("cert", "cert")); 24 | assertThat(serialized, JsonMatcher.hasEntry("subject", "subject")); 25 | } 26 | 27 | @Test 28 | public void shouldDeserialize() throws Exception { 29 | EncryptionKey key = fromJSON(json, EncryptionKey.class); 30 | 31 | assertThat(key, is(notNullValue())); 32 | 33 | assertThat(key.getPub(), is("pub")); 34 | assertThat(key.getCert(), is("cert")); 35 | assertThat(key.getSubject(), is("subject")); 36 | } 37 | } -------------------------------------------------------------------------------- /src/test/java/com/auth0/json/mgmt/client/AndroidTest.java: -------------------------------------------------------------------------------- 1 | package com.auth0.json.mgmt.client; 2 | 3 | import com.auth0.json.JsonMatcher; 4 | import com.auth0.json.JsonTest; 5 | import org.junit.Test; 6 | 7 | import java.util.Arrays; 8 | 9 | import static org.hamcrest.MatcherAssert.assertThat; 10 | import static org.hamcrest.Matchers.*; 11 | 12 | public class AndroidTest extends JsonTest { 13 | 14 | private static final String json = "{\"app_package_name\":\"pkg\",\"sha256_cert_fingerprints\":[\"cert1\",\"cert2\"]}"; 15 | 16 | @Test 17 | public void shouldSerialize() throws Exception { 18 | Android android = new Android("pkg", Arrays.asList("cert1", "cert2")); 19 | 20 | String serialized = toJSON(android); 21 | assertThat(serialized, is(notNullValue())); 22 | assertThat(serialized, JsonMatcher.hasEntry("app_package_name", "pkg")); 23 | assertThat(serialized, JsonMatcher.hasEntry("sha256_cert_fingerprints", Arrays.asList("cert1", "cert2"))); 24 | } 25 | 26 | 27 | @Test 28 | public void shouldDeserialize() throws Exception { 29 | Android android = fromJSON(json, Android.class); 30 | 31 | assertThat(android, is(notNullValue())); 32 | 33 | assertThat(android.getAppPackageName(), is("pkg")); 34 | assertThat(android.getSHA256CertFingerprints(), contains("cert1", "cert2")); 35 | assertThat(android.getSHA256CertFingerprints().size(), is(2)); 36 | } 37 | } -------------------------------------------------------------------------------- /src/test/java/com/auth0/json/mgmt/logevents/LogEventTest.java: -------------------------------------------------------------------------------- 1 | package com.auth0.json.mgmt.logevents; 2 | 3 | import com.auth0.json.JsonTest; 4 | import org.junit.Test; 5 | 6 | import static org.hamcrest.MatcherAssert.assertThat; 7 | import static org.hamcrest.Matchers.is; 8 | import static org.hamcrest.Matchers.notNullValue; 9 | 10 | public class LogEventTest extends JsonTest { 11 | 12 | private static final String json = "{\"_id\":\"123\", \"date\":\"2016-02-23T19:57:29.532Z\",\"type\":\"thetype\",\"location_info\":{},\"details\":{},\"client_id\":\"clientId\",\"client_name\":\"clientName\",\"ip\":\"233.233.233.11\",\"user_id\":\"userId\"}"; 13 | 14 | @Test 15 | public void shouldDeserialize() throws Exception { 16 | LogEvent logEvent = fromJSON(json, LogEvent.class); 17 | 18 | assertThat(logEvent, is(notNullValue())); 19 | assertThat(logEvent.getId(), is("123")); 20 | assertThat(logEvent.getDate(), is(parseJSONDate("2016-02-23T19:57:29.532Z"))); 21 | assertThat(logEvent.getType(), is("thetype")); 22 | assertThat(logEvent.getClientId(), is("clientId")); 23 | assertThat(logEvent.getClientName(), is("clientName")); 24 | assertThat(logEvent.getIP(), is("233.233.233.11")); 25 | assertThat(logEvent.getUserId(), is("userId")); 26 | assertThat(logEvent.getLocationInfo(), is(notNullValue())); 27 | assertThat(logEvent.getDetails(), is(notNullValue())); 28 | } 29 | } -------------------------------------------------------------------------------- /src/main/java/com/auth0/json/mgmt/DailyStats.java: -------------------------------------------------------------------------------- 1 | package com.auth0.json.mgmt; 2 | 3 | import com.fasterxml.jackson.annotation.JsonFormat; 4 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 5 | import com.fasterxml.jackson.annotation.JsonInclude; 6 | import com.fasterxml.jackson.annotation.JsonProperty; 7 | 8 | import java.util.Date; 9 | 10 | /** 11 | * Class that represents an Auth0 Daily Stats object. Related to the {@link com.auth0.client.mgmt.StatsEntity} entity. 12 | */ 13 | @SuppressWarnings({"unused", "WeakerAccess"}) 14 | @JsonIgnoreProperties(ignoreUnknown = true) 15 | @JsonInclude(JsonInclude.Include.NON_NULL) 16 | public class DailyStats { 17 | 18 | @JsonProperty("logins") 19 | private Integer logins; 20 | @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") 21 | @JsonProperty("date") 22 | private Date date; 23 | 24 | /** 25 | * Getter for the amount of logins on the date 26 | * 27 | * @return the amount of logins 28 | */ 29 | @JsonProperty("logins") 30 | public Integer getLogins() { 31 | return logins; 32 | } 33 | 34 | /** 35 | * Getter for the date to which the stats belong 36 | * 37 | * @return the date to which the stats belong 38 | */ 39 | @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") 40 | @JsonProperty("date") 41 | public Date getDate() { 42 | return date; 43 | } 44 | } -------------------------------------------------------------------------------- /src/test/java/com/auth0/client/mgmt/filter/FieldFilterTest.java: -------------------------------------------------------------------------------- 1 | package com.auth0.client.mgmt.filter; 2 | 3 | import org.hamcrest.Matchers; 4 | import org.junit.Before; 5 | import org.junit.Test; 6 | 7 | import static org.hamcrest.CoreMatchers.is; 8 | import static org.hamcrest.CoreMatchers.notNullValue; 9 | import static org.junit.Assert.assertThat; 10 | 11 | public class FieldFilterTest { 12 | 13 | private FieldsFilter filter; 14 | 15 | @Before 16 | public void setUp() throws Exception { 17 | filter = new FieldsFilter(); 18 | } 19 | 20 | @Test 21 | public void shouldFilterWithFields() throws Exception { 22 | FieldsFilter instance = filter.withFields("a,b,c", true); 23 | 24 | assertThat(filter, is(instance)); 25 | assertThat(filter.getAsMap(), is(notNullValue())); 26 | assertThat(filter.getAsMap(), Matchers.hasEntry("fields", (Object) "a,b,c")); 27 | assertThat(filter.getAsMap(), Matchers.hasEntry("include_fields", (Object) true)); 28 | } 29 | 30 | @Test 31 | public void shouldFilterWithoutFields() throws Exception { 32 | FieldsFilter instance = filter.withFields("a,b,c", false); 33 | 34 | assertThat(filter, is(instance)); 35 | assertThat(filter.getAsMap(), is(notNullValue())); 36 | assertThat(filter.getAsMap(), Matchers.hasEntry("fields", (Object) "a,b,c")); 37 | assertThat(filter.getAsMap(), Matchers.hasEntry("include_fields", (Object) false)); 38 | } 39 | } -------------------------------------------------------------------------------- /src/test/resources/mgmt/resource_servers_paged_list.json: -------------------------------------------------------------------------------- 1 | { 2 | "start": 0, 3 | "length": 14, 4 | "total": 14, 5 | "limit": 50, 6 | "resource_servers": [ 7 | { 8 | "id": "23445566abab", 9 | "name": "Some API", 10 | "identifier": "https://api.my-company.com/api/v2/", 11 | "signing_alg": "RS256", 12 | "token_lifetime": 86400, 13 | "token_lifetime_for_web": 7200, 14 | "allow_offline_access": false, 15 | "skip_consent_for_verifiable_first_party_clients": false, 16 | "scopes": [ 17 | { 18 | "description": "Read Client Grants", 19 | "value": "read:client_grants" 20 | }, 21 | { 22 | "description": "Create Client Grants", 23 | "value": "create:client_grants" 24 | } 25 | ], 26 | "is_system": true 27 | }, 28 | { 29 | "id": "3223232da", 30 | "name": "Another API", 31 | "identifier": "https://another-api.my-company.com/api/v2/", 32 | "signing_alg": "RS256", 33 | "token_lifetime": 86400, 34 | "token_lifetime_for_web": 7200, 35 | "allow_offline_access": false, 36 | "skip_consent_for_verifiable_first_party_clients": false, 37 | "scopes": [ 38 | { 39 | "description": "Read Client Grants", 40 | "value": "read:client_grants" 41 | }, 42 | { 43 | "description": "Create Client Grants", 44 | "value": "create:client_grants" 45 | } 46 | ], 47 | "is_system": true 48 | } 49 | ] 50 | } -------------------------------------------------------------------------------- /src/test/java/com/auth0/json/mgmt/guardian/EnrollmentTest.java: -------------------------------------------------------------------------------- 1 | package com.auth0.json.mgmt.guardian; 2 | 3 | import com.auth0.json.JsonTest; 4 | import org.junit.Test; 5 | 6 | import static org.hamcrest.MatcherAssert.assertThat; 7 | import static org.hamcrest.Matchers.is; 8 | import static org.hamcrest.Matchers.notNullValue; 9 | 10 | public class EnrollmentTest extends JsonTest { 11 | 12 | private static final String json = "{\"id\":\"123\",\"status\":\"confirmed\",\"type\":\"idk\",\"name\":\"auth0\",\"identifier\":\"id123\",\"phone_number\":\"1234567890\", \"auth_method\":\"authenticator\",\"enrolled_at\":\"2016-02-23T19:57:29.532Z\",\"last_auth\":\"2016-02-23T19:57:29.532Z\"}"; 13 | 14 | @Test 15 | public void shouldDeserialize() throws Exception { 16 | Enrollment enrollment = fromJSON(json, Enrollment.class); 17 | 18 | assertThat(enrollment, is(notNullValue())); 19 | assertThat(enrollment.getId(), is("123")); 20 | assertThat(enrollment.getStatus(), is("confirmed")); 21 | assertThat(enrollment.getType(), is("idk")); 22 | assertThat(enrollment.getName(), is("auth0")); 23 | assertThat(enrollment.getIdentifier(), is("id123")); 24 | assertThat(enrollment.getPhoneNumber(), is("1234567890")); 25 | assertThat(enrollment.getAuthMethod(), is("authenticator")); 26 | assertThat(enrollment.getEnrolledAt(), is(parseJSONDate("2016-02-23T19:57:29.532Z"))); 27 | assertThat(enrollment.getLastAuth(), is(parseJSONDate("2016-02-23T19:57:29.532Z"))); 28 | } 29 | } -------------------------------------------------------------------------------- /src/main/java/com/auth0/client/mgmt/filter/DeviceCredentialsFilter.java: -------------------------------------------------------------------------------- 1 | package com.auth0.client.mgmt.filter; 2 | 3 | /** 4 | * Class used to filter the results received when calling the Device Credentials endpoint. Related to the {@link com.auth0.client.mgmt.DeviceCredentialsEntity} entity. 5 | */ 6 | public class DeviceCredentialsFilter extends FieldsFilter { 7 | 8 | /** 9 | * Filter by user id 10 | * 11 | * @param userId only retrieve items with this user id. 12 | * @return this filter instance. 13 | */ 14 | public DeviceCredentialsFilter withUserId(String userId) { 15 | parameters.put("user_id", userId); 16 | return this; 17 | } 18 | 19 | /** 20 | * Filter by application's client id 21 | * 22 | * @param clientId only retrieve items with this client id. 23 | * @return this filter instance. 24 | */ 25 | public DeviceCredentialsFilter withClientId(String clientId) { 26 | parameters.put("client_id", clientId); 27 | return this; 28 | } 29 | 30 | /** 31 | * Filter by type 32 | * 33 | * @param type only retrieve items with this type. 34 | * @return this filter instance. 35 | */ 36 | public DeviceCredentialsFilter withType(String type) { 37 | parameters.put("type", type); 38 | return this; 39 | } 40 | 41 | @Override 42 | public DeviceCredentialsFilter withFields(String fields, boolean includeFields) { 43 | super.withFields(fields, includeFields); 44 | return this; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/test/java/com/auth0/json/mgmt/users/ProfileDataTest.java: -------------------------------------------------------------------------------- 1 | package com.auth0.json.mgmt.users; 2 | 3 | import com.auth0.json.JsonTest; 4 | import org.junit.Test; 5 | 6 | import static org.hamcrest.MatcherAssert.assertThat; 7 | import static org.hamcrest.Matchers.is; 8 | import static org.hamcrest.Matchers.notNullValue; 9 | import static org.hamcrest.collection.IsMapContaining.hasEntry; 10 | 11 | public class ProfileDataTest extends JsonTest { 12 | 13 | private static final String json = "{\"email\":\"me@auth0.com\",\"email_verified\":true,\"name\":\"John\", \"username\":\"usr\", \"given_name\":\"John\", \"family_name\":\"Walker\", \"phone_number\":\"1234567890\", \"phone_verified\":true, \"description\":\"My description\"}"; 14 | 15 | @Test 16 | public void shouldDeserialize() throws Exception { 17 | ProfileData data = fromJSON(json, ProfileData.class); 18 | 19 | assertThat(data, is(notNullValue())); 20 | assertThat(data.getEmail(), is("me@auth0.com")); 21 | assertThat(data.isEmailVerified(), is(true)); 22 | assertThat(data.getName(), is("John")); 23 | assertThat(data.getUsername(), is("usr")); 24 | assertThat(data.getGivenName(), is("John")); 25 | assertThat(data.getFamilyName(), is("Walker")); 26 | assertThat(data.getPhoneNumber(), is("1234567890")); 27 | assertThat(data.isPhoneVerified(), is(true)); 28 | assertThat(data.getValues(), is(notNullValue())); 29 | assertThat(data.getValues(), hasEntry("description", (Object) "My description")); 30 | } 31 | } -------------------------------------------------------------------------------- /src/test/java/com/auth0/json/mgmt/tickets/EmailVerificationTicketTest.java: -------------------------------------------------------------------------------- 1 | package com.auth0.json.mgmt.tickets; 2 | 3 | import com.auth0.json.JsonMatcher; 4 | import com.auth0.json.JsonTest; 5 | import org.junit.Test; 6 | 7 | import static org.hamcrest.MatcherAssert.assertThat; 8 | import static org.hamcrest.Matchers.is; 9 | import static org.hamcrest.Matchers.notNullValue; 10 | 11 | public class EmailVerificationTicketTest extends JsonTest { 12 | 13 | private static final String readOnlyJson = "{\"ticket\":\"https://page.auth0.com/tickets/123\"}"; 14 | 15 | @Test 16 | public void shouldSerialize() throws Exception { 17 | EmailVerificationTicket ticket = new EmailVerificationTicket("usr123"); 18 | ticket.setResultUrl("https://page.auth0.com/result"); 19 | ticket.setTTLSeconds(36000); 20 | 21 | String serialized = toJSON(ticket); 22 | assertThat(serialized, is(notNullValue())); 23 | assertThat(serialized, JsonMatcher.hasEntry("user_id", "usr123")); 24 | assertThat(serialized, JsonMatcher.hasEntry("result_url", "https://page.auth0.com/result")); 25 | assertThat(serialized, JsonMatcher.hasEntry("ttl_sec", 36000)); 26 | } 27 | 28 | @Test 29 | public void shouldIncludeReadOnlyValuesOnDeserialize() throws Exception { 30 | EmailVerificationTicket ticket = fromJSON(readOnlyJson, EmailVerificationTicket.class); 31 | assertThat(ticket, is(notNullValue())); 32 | 33 | assertThat(ticket.getTicket(), is("https://page.auth0.com/tickets/123")); 34 | } 35 | 36 | } -------------------------------------------------------------------------------- /src/main/java/com/auth0/json/mgmt/client/EncryptionKey.java: -------------------------------------------------------------------------------- 1 | package com.auth0.json.mgmt.client; 2 | 3 | import com.fasterxml.jackson.annotation.JsonCreator; 4 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 5 | import com.fasterxml.jackson.annotation.JsonInclude; 6 | import com.fasterxml.jackson.annotation.JsonProperty; 7 | 8 | @SuppressWarnings({"WeakerAccess", "unused"}) 9 | @JsonIgnoreProperties(ignoreUnknown = true) 10 | @JsonInclude(JsonInclude.Include.NON_NULL) 11 | public class EncryptionKey { 12 | 13 | @JsonProperty("pub") 14 | private String pub; 15 | @JsonProperty("cert") 16 | private String cert; 17 | @JsonProperty("subject") 18 | private String subject; 19 | 20 | @JsonCreator 21 | public EncryptionKey(@JsonProperty("pub") String pub, @JsonProperty("cert") String cert) { 22 | this.pub = pub; 23 | this.cert = cert; 24 | } 25 | 26 | @JsonProperty("pub") 27 | public String getPub() { 28 | return pub; 29 | } 30 | 31 | @JsonProperty("pub") 32 | public void setPub(String pub) { 33 | this.pub = pub; 34 | } 35 | 36 | @JsonProperty("cert") 37 | public String getCert() { 38 | return cert; 39 | } 40 | 41 | @JsonProperty("cert") 42 | public void setCert(String cert) { 43 | this.cert = cert; 44 | } 45 | 46 | @JsonProperty("subject") 47 | public String getSubject() { 48 | return subject; 49 | } 50 | 51 | @JsonProperty("subject") 52 | public void setSubject(String subject) { 53 | this.subject = subject; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/test/java/com/auth0/json/JsonTest.java: -------------------------------------------------------------------------------- 1 | package com.auth0.json; 2 | 3 | import java.io.IOException; 4 | import java.nio.file.Files; 5 | import java.nio.file.Paths; 6 | import java.text.ParseException; 7 | import java.text.SimpleDateFormat; 8 | import java.util.Date; 9 | import java.util.TimeZone; 10 | 11 | import com.fasterxml.jackson.core.JsonProcessingException; 12 | import com.fasterxml.jackson.core.type.TypeReference; 13 | import com.fasterxml.jackson.databind.ObjectMapper; 14 | 15 | public class JsonTest { 16 | 17 | private static final String DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"; 18 | 19 | private ObjectMapper mapper; 20 | 21 | public JsonTest() { 22 | this.mapper = new ObjectMapper(); 23 | } 24 | 25 | public String toJSON(T value) throws JsonProcessingException { 26 | return mapper.writeValueAsString(value); 27 | } 28 | 29 | public T fromJSON(String json, Class tClazz) throws IOException { 30 | return mapper.readValue(json, tClazz); 31 | } 32 | 33 | public T fromJSON(String json, TypeReference tReference) throws IOException { 34 | return mapper.readValue(json, tReference); 35 | } 36 | 37 | public String readTextFile(String path) throws IOException { 38 | return new String(Files.readAllBytes(Paths.get(path))); 39 | } 40 | 41 | protected Date parseJSONDate(String dateString) throws ParseException { 42 | SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT); 43 | sdf.setTimeZone(TimeZone.getTimeZone("UTC")); 44 | return sdf.parse(dateString); 45 | } 46 | } -------------------------------------------------------------------------------- /src/main/java/com/auth0/json/mgmt/jobs/Job.java: -------------------------------------------------------------------------------- 1 | package com.auth0.json.mgmt.jobs; 2 | 3 | import com.fasterxml.jackson.annotation.*; 4 | 5 | import java.util.Date; 6 | 7 | /** 8 | * Class that represents an Auth0 Job object. Related to the {@link com.auth0.client.mgmt.JobsEntity} entity. 9 | */ 10 | @SuppressWarnings({"unused", "WeakerAccess"}) 11 | @JsonIgnoreProperties(ignoreUnknown = true) 12 | @JsonInclude(JsonInclude.Include.NON_NULL) 13 | public class Job { 14 | 15 | @JsonProperty("status") 16 | private String status; 17 | @JsonProperty("type") 18 | private String type; 19 | @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") 20 | @JsonProperty("created_at") 21 | private Date createdAt; 22 | @JsonProperty("id") 23 | private String id; 24 | 25 | @JsonCreator 26 | private Job(@JsonProperty("status") String status, @JsonProperty("type") String type, @JsonProperty("id") String id) { 27 | this.status = status; 28 | this.type = type; 29 | this.id = id; 30 | } 31 | 32 | @JsonProperty("status") 33 | public String getStatus() { 34 | return status; 35 | } 36 | 37 | @JsonProperty("type") 38 | public String getType() { 39 | return type; 40 | } 41 | 42 | @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") 43 | @JsonProperty("created_at") 44 | public Date getCreatedAt() { 45 | return createdAt; 46 | } 47 | 48 | @JsonProperty("id") 49 | public String getId() { 50 | return id; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/com/auth0/client/mgmt/filter/LogEventFilter.java: -------------------------------------------------------------------------------- 1 | package com.auth0.client.mgmt.filter; 2 | 3 | /** 4 | * Class used to filter the results received when calling the Logs endpoint. Related to the {@link com.auth0.client.mgmt.LogEventsEntity} entity. 5 | */ 6 | public class LogEventFilter extends QueryFilter { 7 | 8 | /** 9 | * Filter by checkpoint 10 | * 11 | * @param from the log event id to start retrieving logs from. 12 | * @param take the limit of items to retrieve. 13 | * @return this filter instance 14 | */ 15 | public LogEventFilter withCheckpoint(String from, int take) { 16 | parameters.put("from", from); 17 | parameters.put("take", take); 18 | return this; 19 | } 20 | 21 | @Override 22 | public LogEventFilter withTotals(boolean includeTotals) { 23 | super.withTotals(includeTotals); 24 | return this; 25 | } 26 | 27 | @Override 28 | public LogEventFilter withQuery(String query) { 29 | super.withQuery(query); 30 | return this; 31 | } 32 | 33 | @Override 34 | public LogEventFilter withSort(String sort) { 35 | super.withSort(sort); 36 | return this; 37 | } 38 | 39 | @Override 40 | public LogEventFilter withPage(int pageNumber, int amountPerPage) { 41 | super.withPage(pageNumber, amountPerPage); 42 | return this; 43 | } 44 | 45 | @Override 46 | public LogEventFilter withFields(String fields, boolean includeFields) { 47 | super.withFields(fields, includeFields); 48 | return this; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/test/java/com/auth0/json/mgmt/client/AddonTest.java: -------------------------------------------------------------------------------- 1 | package com.auth0.json.mgmt.client; 2 | 3 | import com.auth0.json.JsonMatcher; 4 | import com.auth0.json.JsonTest; 5 | import org.hamcrest.collection.IsMapContaining; 6 | import org.junit.Test; 7 | 8 | import static org.hamcrest.MatcherAssert.assertThat; 9 | import static org.hamcrest.Matchers.is; 10 | import static org.hamcrest.Matchers.notNullValue; 11 | 12 | public class AddonTest extends JsonTest { 13 | 14 | private static final String json = "{\"a-boolean\":true,\"a-string\":\"string\"}"; 15 | 16 | @Test 17 | public void shouldSerialize() throws Exception { 18 | Addon addon = new Addon(); 19 | addon.setProperty("a-boolean", true); 20 | addon.setProperty("a-string", "string"); 21 | 22 | String serialized = toJSON(addon); 23 | assertThat(serialized, is(notNullValue())); 24 | assertThat(serialized, JsonMatcher.hasEntry("a-boolean", true)); 25 | assertThat(serialized, JsonMatcher.hasEntry("a-string", "string")); 26 | } 27 | 28 | @Test 29 | public void shouldDeserialize() throws Exception { 30 | Addon addon = fromJSON(json, Addon.class); 31 | 32 | assertThat(addon, is(notNullValue())); 33 | 34 | assertThat(addon.getProperties(), IsMapContaining.hasEntry("a-boolean", (Object) true)); 35 | assertThat(addon.getProperties(), IsMapContaining.hasEntry("a-string", (Object) "string")); 36 | assertThat(addon.getProperty("a-boolean"), is((Object) true)); 37 | assertThat(addon.getProperty("a-string"), is((Object) "string")); 38 | } 39 | } -------------------------------------------------------------------------------- /src/main/java/com/auth0/net/Telemetry.java: -------------------------------------------------------------------------------- 1 | package com.auth0.net; 2 | 3 | import com.fasterxml.jackson.core.JsonProcessingException; 4 | import com.fasterxml.jackson.databind.ObjectMapper; 5 | import org.apache.commons.codec.binary.Base64; 6 | 7 | import java.util.HashMap; 8 | import java.util.Map; 9 | 10 | @SuppressWarnings("WeakerAccess") 11 | class Telemetry { 12 | static final String HEADER_NAME = "Auth0-Client"; 13 | 14 | private static final String NAME_KEY = "name"; 15 | private static final String VERSION_KEY = "version"; 16 | 17 | private final String name; 18 | private final String version; 19 | 20 | Telemetry(String name, String version) { 21 | this.name = name; 22 | this.version = version; 23 | } 24 | 25 | public String getName() { 26 | return name; 27 | } 28 | 29 | public String getVersion() { 30 | return version; 31 | } 32 | 33 | public String getValue() { 34 | Map values = new HashMap<>(); 35 | if (name != null) { 36 | values.put(NAME_KEY, name); 37 | } 38 | if (version != null) { 39 | values.put(VERSION_KEY, version); 40 | } 41 | if (values.isEmpty()) { 42 | return null; 43 | } 44 | String urlSafe = null; 45 | try { 46 | String json = new ObjectMapper().writeValueAsString(values); 47 | urlSafe = Base64.encodeBase64URLSafeString(json.getBytes()); 48 | } catch (JsonProcessingException e) { 49 | e.printStackTrace(); 50 | } 51 | return urlSafe; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/test/resources/mgmt/client.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "My 1 application", 3 | "client_id": "AaiyAPdpYdesoKnqjj8HJqRn4T5titww", 4 | "client_secret": "MG_TNT2ver-SylNat-_VeMmd-4m0Waba0jr1troztBniSChEw0glxEmgEi2Kw40H", 5 | "logo_uri": "https://my.logo.com/uri", 6 | "callbacks": [ 7 | "https://domain.auth0.com/callback" 8 | ], 9 | "allowed_origins": [ 10 | "https://domain.auth0.com" 11 | ], 12 | "client_aliases": [ 13 | "https://domain.auth0.com" 14 | ], 15 | "allowed_clients": [ 16 | "clientId1" 17 | ], 18 | "allowed_logout_urls": [ 19 | "https://domain.auth0.com/logout" 20 | ], 21 | "token_endpoint_auth_method": "code", 22 | "app_type": "native", 23 | "oidc_conformant": false, 24 | "jwt_configuration": { 25 | "lifetime_in_seconds": 100, 26 | "secret_encoded": true, 27 | "scopes": {}, 28 | "alg": "HS256" 29 | }, 30 | "encryption_key": { 31 | "pub": "", 32 | "cert": "" 33 | }, 34 | "sso": false, 35 | "sso_disabled": false, 36 | "custom_login_page_on": false, 37 | "custom_login_page": "", 38 | "custom_login_page_preview": "", 39 | "form_template": "", 40 | "is_heroku_app": false, 41 | "addons": { 42 | "rms": {}, 43 | "slack": { 44 | "team": "Auth0" 45 | }, 46 | "mscrm": {}, 47 | "layer": {}, 48 | "zoom": {} 49 | }, 50 | "client_metadata": {}, 51 | "mobile": { 52 | "android": { 53 | "app_package_name": "com.example", 54 | "sha256_cert_fingerprints": [ 55 | "D8:A0:83:..." 56 | ] 57 | }, 58 | "ios": { 59 | "team_id": "9JA89QQLNQ", 60 | "app_bundle_identifier": "com.my.bundle.id" 61 | } 62 | } 63 | } -------------------------------------------------------------------------------- /src/main/java/com/auth0/client/mgmt/filter/RulesFilter.java: -------------------------------------------------------------------------------- 1 | package com.auth0.client.mgmt.filter; 2 | 3 | /** 4 | * Class used to filter the results received when calling the Rules endpoint. Related to the {@link com.auth0.client.mgmt.RulesEntity} entity. 5 | */ 6 | public class RulesFilter extends FieldsFilter { 7 | 8 | /** 9 | * Filter by enabled value 10 | * 11 | * @param enabled only retrieve items that are enabled or disabled. 12 | * @return this filter instance. 13 | */ 14 | public RulesFilter withEnabled(boolean enabled) { 15 | parameters.put("enabled", enabled); 16 | return this; 17 | } 18 | 19 | @Override 20 | public RulesFilter withFields(String fields, boolean includeFields) { 21 | super.withFields(fields, includeFields); 22 | return this; 23 | } 24 | 25 | /** 26 | * Include the query summary 27 | * Warning: Can only be used with {@link com.auth0.client.mgmt.RulesEntity#listAll(RulesFilter)} 28 | * 29 | * @param includeTotals whether to include or not the query summary. 30 | * @return this filter instance 31 | */ 32 | public RulesFilter withTotals(boolean includeTotals) { 33 | parameters.put("include_totals", includeTotals); 34 | return this; 35 | } 36 | 37 | /** 38 | * Filter by page 39 | * 40 | * @param pageNumber the page number to retrieve. 41 | * @param amountPerPage the amount of items per page to retrieve. 42 | * @return this filter instance 43 | */ 44 | public RulesFilter withPage(int pageNumber, int amountPerPage) { 45 | parameters.put("page", pageNumber); 46 | parameters.put("per_page", amountPerPage); 47 | return this; 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /src/test/java/com/auth0/net/VoidRequestTest.java: -------------------------------------------------------------------------------- 1 | package com.auth0.net; 2 | 3 | import com.auth0.client.MockServer; 4 | import okhttp3.OkHttpClient; 5 | import okhttp3.mockwebserver.RecordedRequest; 6 | import org.junit.Before; 7 | import org.junit.Test; 8 | 9 | import static com.auth0.client.MockServer.AUTH_TOKENS; 10 | import static org.hamcrest.Matchers.*; 11 | import static org.junit.Assert.assertThat; 12 | 13 | public class VoidRequestTest { 14 | private OkHttpClient client; 15 | private MockServer server; 16 | 17 | @Before 18 | public void setUp() throws Exception { 19 | client = new OkHttpClient(); 20 | server = new MockServer(); 21 | } 22 | 23 | @Test 24 | public void shouldCreateGETRequest() throws Exception { 25 | VoidRequest request = new VoidRequest(client, server.getBaseUrl(), "GET"); 26 | assertThat(request, is(notNullValue())); 27 | 28 | server.jsonResponse(AUTH_TOKENS, 200); 29 | Void execute = request.execute(); 30 | RecordedRequest recordedRequest = server.takeRequest(); 31 | assertThat(recordedRequest.getMethod(), is("GET")); 32 | assertThat(execute, is(nullValue())); 33 | } 34 | 35 | @Test 36 | public void shouldCreatePOSTRequest() throws Exception { 37 | VoidRequest request = new VoidRequest(client, server.getBaseUrl(), "POST"); 38 | assertThat(request, is(notNullValue())); 39 | request.addParameter("non_empty", "body"); 40 | 41 | server.jsonResponse(AUTH_TOKENS, 200); 42 | Void execute = request.execute(); 43 | RecordedRequest recordedRequest = server.takeRequest(); 44 | assertThat(recordedRequest.getMethod(), is("POST")); 45 | assertThat(execute, is(nullValue())); 46 | } 47 | 48 | } -------------------------------------------------------------------------------- /src/main/java/com/auth0/json/mgmt/tenants/PageCustomization.java: -------------------------------------------------------------------------------- 1 | package com.auth0.json.mgmt.tenants; 2 | 3 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 4 | import com.fasterxml.jackson.annotation.JsonInclude; 5 | import com.fasterxml.jackson.annotation.JsonProperty; 6 | 7 | @SuppressWarnings({"unused", "WeakerAccess"}) 8 | @JsonIgnoreProperties(ignoreUnknown = true) 9 | @JsonInclude(JsonInclude.Include.NON_NULL) 10 | public class PageCustomization { 11 | 12 | @JsonProperty("enabled") 13 | private Boolean enabled; 14 | @JsonProperty("html") 15 | private String html; 16 | 17 | /** 18 | * Whether the custom page will be used instead of the default one or not. 19 | * 20 | * @return true if the custom page will be used instead of the default one, false otherwise. 21 | */ 22 | @JsonProperty("enabled") 23 | public Boolean isEnabled() { 24 | return enabled; 25 | } 26 | 27 | /** 28 | * Sets if the custom page will be used instead of the default one or not. 29 | * 30 | * @param enabled whether the custom page will be used instead of the default one, false otherwise. 31 | */ 32 | @JsonProperty("enabled") 33 | public void setEnabled(Boolean enabled) { 34 | this.enabled = enabled; 35 | } 36 | 37 | /** 38 | * Getter for the page custom HTML code. 39 | * 40 | * @return the HTML code. 41 | */ 42 | @JsonProperty("html") 43 | public String getHTML() { 44 | return html; 45 | } 46 | 47 | /** 48 | * Setter for the page custom HTML code. 49 | * 50 | * @param html the HTML code to set. 51 | */ 52 | @JsonProperty("html") 53 | public void setHTML(String html) { 54 | this.html = html; 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/com/auth0/client/mgmt/filter/GrantsFilter.java: -------------------------------------------------------------------------------- 1 | package com.auth0.client.mgmt.filter; 2 | 3 | /** 4 | * Class used to filter the results received when calling the Grants endpoint. Related to the {@link com.auth0.client.mgmt.GrantsEntity} entity. 5 | */ 6 | public class GrantsFilter extends BaseFilter { 7 | 8 | /** 9 | * Filter by client id 10 | * 11 | * @param clientId only retrieve items with this client id. 12 | * @return this filter instance 13 | */ 14 | public GrantsFilter withClientId(String clientId) { 15 | parameters.put("client_id", clientId); 16 | return this; 17 | } 18 | 19 | /** 20 | * Filter by audience 21 | * 22 | * @param audience only retrieve the item with this audience. 23 | * @return this filter instance 24 | */ 25 | public GrantsFilter withAudience(String audience) { 26 | parameters.put("audience", audience); 27 | return this; 28 | } 29 | 30 | /** 31 | * Filter by page 32 | * 33 | * @param pageNumber the page number to retrieve. 34 | * @param amountPerPage the amount of items per page to retrieve. 35 | * @return this filter instance 36 | */ 37 | public GrantsFilter withPage(int pageNumber, int amountPerPage) { 38 | parameters.put("page", pageNumber); 39 | parameters.put("per_page", amountPerPage); 40 | return this; 41 | } 42 | 43 | /** 44 | * Include the query summary 45 | * 46 | * @param includeTotals whether to include or not the query summary. 47 | * @return this filter instance 48 | */ 49 | public GrantsFilter withTotals(boolean includeTotals) { 50 | parameters.put("include_totals", includeTotals); 51 | return this; 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/com/auth0/client/mgmt/filter/ClientGrantsFilter.java: -------------------------------------------------------------------------------- 1 | package com.auth0.client.mgmt.filter; 2 | 3 | /** 4 | * Class used to filter the results received when calling the Client Grants endpoint. Related to the {@link com.auth0.client.mgmt.ClientGrantsEntity} entity. 5 | */ 6 | public class ClientGrantsFilter extends BaseFilter { 7 | 8 | /** 9 | * Filter by client id 10 | * 11 | * @param clientId only retrieve items with this client id. 12 | * @return this filter instance 13 | */ 14 | public ClientGrantsFilter withClientId(String clientId) { 15 | parameters.put("client_id", clientId); 16 | return this; 17 | } 18 | 19 | /** 20 | * Filter by audience 21 | * 22 | * @param audience only retrieve the item with this audience. 23 | * @return this filter instance 24 | */ 25 | public ClientGrantsFilter withAudience(String audience) { 26 | parameters.put("audience", audience); 27 | return this; 28 | } 29 | 30 | /** 31 | * Filter by page 32 | * 33 | * @param pageNumber the page number to retrieve. 34 | * @param amountPerPage the amount of items per page to retrieve. 35 | * @return this filter instance 36 | */ 37 | public ClientGrantsFilter withPage(int pageNumber, int amountPerPage) { 38 | parameters.put("page", pageNumber); 39 | parameters.put("per_page", amountPerPage); 40 | return this; 41 | } 42 | 43 | /** 44 | * Include the query summary 45 | * 46 | * @param includeTotals whether to include or not the query summary. 47 | * @return this filter instance 48 | */ 49 | public ClientGrantsFilter withTotals(boolean includeTotals) { 50 | parameters.put("include_totals", includeTotals); 51 | return this; 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/com/auth0/json/mgmt/client/Mobile.java: -------------------------------------------------------------------------------- 1 | package com.auth0.json.mgmt.client; 2 | 3 | import com.fasterxml.jackson.annotation.JsonCreator; 4 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 5 | import com.fasterxml.jackson.annotation.JsonInclude; 6 | import com.fasterxml.jackson.annotation.JsonProperty; 7 | 8 | @SuppressWarnings({"unused", "WeakerAccess"}) 9 | @JsonIgnoreProperties(ignoreUnknown = true) 10 | @JsonInclude(JsonInclude.Include.NON_NULL) 11 | public class Mobile { 12 | 13 | @JsonProperty("android") 14 | private Android android; 15 | @JsonProperty("ios") 16 | private IOS ios; 17 | 18 | @JsonCreator 19 | public Mobile(@JsonProperty("android") Android android, @JsonProperty("ios") IOS ios) { 20 | this.android = android; 21 | this.ios = ios; 22 | } 23 | 24 | /** 25 | * Getter for the android mobile configuration. 26 | * 27 | * @return the android mobile configuration. 28 | */ 29 | @JsonProperty("android") 30 | public Android getAndroid() { 31 | return android; 32 | } 33 | 34 | /** 35 | * Setter for the Android mobile configuration. 36 | * 37 | * @param android the Android mobile configuration to set. 38 | */ 39 | @JsonProperty("android") 40 | public void setAndroid(Android android) { 41 | this.android = android; 42 | } 43 | 44 | /** 45 | * Getter for the iOS mobile configuration. 46 | * 47 | * @return the iOS mobile configuration. 48 | */ 49 | @JsonProperty("ios") 50 | public IOS getIOS() { 51 | return ios; 52 | } 53 | 54 | /** 55 | * Setter for the iOS mobile configuration. 56 | * 57 | * @param ios the iOS mobile configuration to set. 58 | */ 59 | @JsonProperty("ios") 60 | public void setIOS(IOS ios) { 61 | this.ios = ios; 62 | } 63 | } -------------------------------------------------------------------------------- /src/main/java/com/auth0/json/mgmt/tenants/ErrorPageCustomization.java: -------------------------------------------------------------------------------- 1 | package com.auth0.json.mgmt.tenants; 2 | 3 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 4 | import com.fasterxml.jackson.annotation.JsonInclude; 5 | import com.fasterxml.jackson.annotation.JsonProperty; 6 | 7 | @SuppressWarnings({"unused", "WeakerAccess"}) 8 | @JsonIgnoreProperties(ignoreUnknown = true) 9 | @JsonInclude(JsonInclude.Include.NON_NULL) 10 | public class ErrorPageCustomization extends PageCustomization { 11 | 12 | @JsonProperty("show_log_link") 13 | private Boolean showLogLink; 14 | @JsonProperty("url") 15 | private String url; 16 | 17 | /** 18 | * Whether the error page will show a link to the log or not. 19 | * 20 | * @return true if the error page will show a link to the log, false otherwise. 21 | */ 22 | @JsonProperty("show_log_link") 23 | public Boolean willShowLogLink() { 24 | return showLogLink; 25 | } 26 | 27 | /** 28 | * Sets if the error page will show a link to the log or not. 29 | * 30 | * @param showLogLink whether the error page will show a link to the log or not. 31 | */ 32 | @JsonProperty("show_log_link") 33 | public void setShowLogLink(Boolean showLogLink) { 34 | this.showLogLink = showLogLink; 35 | } 36 | 37 | /** 38 | * Getter for the url to redirect to instead of showing the default error page. 39 | * 40 | * @return the url to redirect to. 41 | */ 42 | @JsonProperty("url") 43 | public String getUrl() { 44 | return url; 45 | } 46 | 47 | /** 48 | * Setter for the url to redirect to instead of showing the default error page. 49 | * 50 | * @param url the url to redirect to. 51 | */ 52 | @JsonProperty("url") 53 | public void setUrl(String url) { 54 | this.url = url; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/com/auth0/json/mgmt/users/Identity.java: -------------------------------------------------------------------------------- 1 | package com.auth0.json.mgmt.users; 2 | 3 | import com.fasterxml.jackson.annotation.*; 4 | 5 | import java.util.HashMap; 6 | import java.util.Map; 7 | 8 | @SuppressWarnings({"unused", "WeakerAccess"}) 9 | @JsonIgnoreProperties(ignoreUnknown = true) 10 | @JsonInclude(JsonInclude.Include.NON_NULL) 11 | public class Identity { 12 | 13 | @JsonProperty("connection") 14 | private String connection; 15 | @JsonProperty("user_id") 16 | private String userId; 17 | @JsonProperty("provider") 18 | private String provider; 19 | @JsonProperty("isSocial") 20 | private Boolean isSocial; 21 | @JsonProperty("access_token") 22 | private String accessToken; 23 | @JsonProperty("profileData") 24 | private ProfileData profileData; 25 | private Map values; 26 | 27 | public Identity() { 28 | values = new HashMap<>(); 29 | } 30 | 31 | @JsonAnySetter 32 | void setValue(String key, Object value) { 33 | values.put(key, value); 34 | } 35 | 36 | @JsonAnyGetter 37 | public Map getValues() { 38 | return values; 39 | } 40 | 41 | @JsonProperty("connection") 42 | public String getConnection() { 43 | return connection; 44 | } 45 | 46 | @JsonProperty("user_id") 47 | public String getUserId() { 48 | return userId; 49 | } 50 | 51 | @JsonProperty("provider") 52 | public String getProvider() { 53 | return provider; 54 | } 55 | 56 | @JsonProperty("isSocial") 57 | public Boolean isSocial() { 58 | return isSocial; 59 | } 60 | 61 | @JsonProperty("access_token") 62 | public String getAccessToken() { 63 | return accessToken; 64 | } 65 | 66 | @JsonProperty("profileData") 67 | public ProfileData getProfileData() { 68 | return profileData; 69 | } 70 | } -------------------------------------------------------------------------------- /src/test/java/com/auth0/json/mgmt/ClientGrantTest.java: -------------------------------------------------------------------------------- 1 | package com.auth0.json.mgmt; 2 | 3 | import com.auth0.json.JsonMatcher; 4 | import com.auth0.json.JsonTest; 5 | import org.junit.Test; 6 | 7 | import java.util.Arrays; 8 | 9 | import static org.hamcrest.MatcherAssert.assertThat; 10 | import static org.hamcrest.Matchers.*; 11 | 12 | public class ClientGrantTest extends JsonTest { 13 | 14 | private static final String json = "{\"client_id\":\"clientId\",\"audience\":\"aud\",\"scope\":[\"one\",\"two\"]}"; 15 | private static final String readOnlyJson = "{\"id\":\"grantId\"}"; 16 | 17 | @Test 18 | public void shouldSerialize() throws Exception { 19 | ClientGrant grant = new ClientGrant(); 20 | grant.setAudience("aud"); 21 | grant.setClientId("clientId"); 22 | grant.setScope(Arrays.asList("one", "two")); 23 | 24 | String serialized = toJSON(grant); 25 | assertThat(serialized, is(notNullValue())); 26 | assertThat(serialized, JsonMatcher.hasEntry("client_id", "clientId")); 27 | assertThat(serialized, JsonMatcher.hasEntry("audience", "aud")); 28 | assertThat(serialized, JsonMatcher.hasEntry("scope", Arrays.asList("one", "two"))); 29 | } 30 | 31 | @Test 32 | public void shouldDeserialize() throws Exception { 33 | ClientGrant grant = fromJSON(json, ClientGrant.class); 34 | 35 | assertThat(grant, is(notNullValue())); 36 | 37 | assertThat(grant.getAudience(), is("aud")); 38 | assertThat(grant.getClientId(), is("clientId")); 39 | assertThat(grant.getScope(), contains("one", "two")); 40 | } 41 | 42 | @Test 43 | public void shouldIncludeReadOnlyValuesOnDeserialize() throws Exception { 44 | ClientGrant grant = fromJSON(readOnlyJson, ClientGrant.class); 45 | assertThat(grant, is(notNullValue())); 46 | 47 | assertThat(grant.getId(), is("grantId")); 48 | } 49 | } -------------------------------------------------------------------------------- /src/test/java/com/auth0/json/mgmt/tickets/PasswordChangeTicketTest.java: -------------------------------------------------------------------------------- 1 | package com.auth0.json.mgmt.tickets; 2 | 3 | import com.auth0.json.JsonMatcher; 4 | import com.auth0.json.JsonTest; 5 | import org.junit.Test; 6 | 7 | import static org.hamcrest.MatcherAssert.assertThat; 8 | import static org.hamcrest.Matchers.is; 9 | import static org.hamcrest.Matchers.notNullValue; 10 | 11 | public class PasswordChangeTicketTest extends JsonTest { 12 | 13 | private static final String readOnlyJson = "{\"ticket\":\"https://page.auth0.com/tickets/123\"}"; 14 | 15 | @Test 16 | public void shouldSerialize() throws Exception { 17 | PasswordChangeTicket ticket = new PasswordChangeTicket("usr123"); 18 | ticket.setResultUrl("https://page.auth0.com/result"); 19 | ticket.setTTLSeconds(36000); 20 | ticket.setConnectionId("12"); 21 | ticket.setEmail("me@auth0.com"); 22 | ticket.setNewPassword("pass123"); 23 | 24 | String serialized = toJSON(ticket); 25 | assertThat(serialized, is(notNullValue())); 26 | assertThat(serialized, JsonMatcher.hasEntry("user_id", "usr123")); 27 | assertThat(serialized, JsonMatcher.hasEntry("result_url", "https://page.auth0.com/result")); 28 | assertThat(serialized, JsonMatcher.hasEntry("ttl_sec", 36000)); 29 | assertThat(serialized, JsonMatcher.hasEntry("new_password", "pass123")); 30 | assertThat(serialized, JsonMatcher.hasEntry("connection_id", "12")); 31 | assertThat(serialized, JsonMatcher.hasEntry("email", "me@auth0.com")); 32 | } 33 | 34 | @Test 35 | public void shouldIncludeReadOnlyValuesOnDeserialize() throws Exception { 36 | PasswordChangeTicket ticket = fromJSON(readOnlyJson, PasswordChangeTicket.class); 37 | assertThat(ticket, is(notNullValue())); 38 | 39 | assertThat(ticket.getTicket(), is("https://page.auth0.com/tickets/123")); 40 | } 41 | 42 | } -------------------------------------------------------------------------------- /src/main/java/com/auth0/json/mgmt/Token.java: -------------------------------------------------------------------------------- 1 | package com.auth0.json.mgmt; 2 | 3 | import com.fasterxml.jackson.annotation.JsonCreator; 4 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 5 | import com.fasterxml.jackson.annotation.JsonInclude; 6 | import com.fasterxml.jackson.annotation.JsonProperty; 7 | 8 | /** 9 | * Class that represents an Auth0 Blacklisted Token object. Related to the {@link com.auth0.client.mgmt.BlacklistsEntity} entity. 10 | */ 11 | @SuppressWarnings({"unused", "WeakerAccess"}) 12 | @JsonIgnoreProperties(ignoreUnknown = true) 13 | @JsonInclude(JsonInclude.Include.NON_NULL) 14 | public class Token { 15 | 16 | @JsonProperty("aud") 17 | private String aud; 18 | @JsonProperty("jti") 19 | private String jti; 20 | 21 | @JsonCreator 22 | public Token(@JsonProperty("jti") String jti) { 23 | this.jti = jti; 24 | } 25 | 26 | /** 27 | * Getter for the JWT's aud claim. This is the client id of the application for which this token was issued. 28 | * 29 | * @return the audience. 30 | */ 31 | @JsonProperty("aud") 32 | public String getAud() { 33 | return aud; 34 | } 35 | 36 | /** 37 | * Setter for the JWT's aud claim. This is the client id of the application for which this token was issued. 38 | * 39 | * @param aud the audience to blacklist. 40 | */ 41 | @JsonProperty("aud") 42 | public void setAud(String aud) { 43 | this.aud = aud; 44 | } 45 | 46 | /** 47 | * Getter for the JWT's jti claim. 48 | * 49 | * @return the audience. 50 | */ 51 | @JsonProperty("jti") 52 | public String getJTI() { 53 | return jti; 54 | } 55 | 56 | /** 57 | * Setter for the JWT's jti to blacklist. 58 | * 59 | * @param jti the jwt identifier to blacklist. 60 | */ 61 | @JsonProperty("jti") 62 | public void setJTI(String jti) { 63 | this.jti = jti; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/test/java/com/auth0/json/mgmt/tenants/ErrorPageCustomizationTest.java: -------------------------------------------------------------------------------- 1 | package com.auth0.json.mgmt.tenants; 2 | 3 | import com.auth0.json.JsonMatcher; 4 | import com.auth0.json.JsonTest; 5 | import org.junit.Test; 6 | 7 | import static org.hamcrest.MatcherAssert.assertThat; 8 | import static org.hamcrest.Matchers.is; 9 | import static org.hamcrest.Matchers.notNullValue; 10 | 11 | public class ErrorPageCustomizationTest extends JsonTest { 12 | 13 | private static final String json = "{\"enabled\":true,\"html\":\"thewebpage\",\"show_log_link\":true,\"url\":\"https://page.auth0.com/main\"}"; 14 | 15 | @Test 16 | public void shouldSerialize() throws Exception { 17 | ErrorPageCustomization customization = new ErrorPageCustomization(); 18 | customization.setEnabled(true); 19 | customization.setHTML("thewebpage"); 20 | customization.setShowLogLink(true); 21 | customization.setUrl("https://page.auth0.com/main"); 22 | 23 | String serialized = toJSON(customization); 24 | assertThat(serialized, is(notNullValue())); 25 | assertThat(serialized, JsonMatcher.hasEntry("enabled", true)); 26 | assertThat(serialized, JsonMatcher.hasEntry("html", "thewebpage")); 27 | assertThat(serialized, JsonMatcher.hasEntry("show_log_link", true)); 28 | assertThat(serialized, JsonMatcher.hasEntry("url", "https://page.auth0.com/main")); 29 | } 30 | 31 | @Test 32 | public void shouldDeserialize() throws Exception { 33 | ErrorPageCustomization customization = fromJSON(json, ErrorPageCustomization.class); 34 | 35 | assertThat(customization, is(notNullValue())); 36 | assertThat(customization.isEnabled(), is(true)); 37 | assertThat(customization.getHTML(), is("thewebpage")); 38 | assertThat(customization.willShowLogLink(), is(true)); 39 | assertThat(customization.getUrl(), is("https://page.auth0.com/main")); 40 | } 41 | 42 | } -------------------------------------------------------------------------------- /src/test/java/com/auth0/json/mgmt/GrantTest.java: -------------------------------------------------------------------------------- 1 | package com.auth0.json.mgmt; 2 | 3 | import com.auth0.json.JsonMatcher; 4 | import com.auth0.json.JsonTest; 5 | import org.junit.Test; 6 | 7 | import java.util.Arrays; 8 | 9 | import static org.hamcrest.MatcherAssert.assertThat; 10 | import static org.hamcrest.Matchers.*; 11 | 12 | public class GrantTest extends JsonTest { 13 | 14 | private static final String json = "{\"clientID\":\"clientId\",\"user_id\":\"userId\",\"audience\":\"aud\",\"scope\":[\"one\",\"two\"]}"; 15 | private static final String readOnlyJson = "{\"id\":\"grantId\"}"; 16 | 17 | @Test 18 | public void shouldSerialize() throws Exception { 19 | Grant grant = new Grant(); 20 | grant.setUserId("userId"); 21 | grant.setAudience("aud"); 22 | grant.setClientId("clientId"); 23 | grant.setScope(Arrays.asList("one", "two")); 24 | 25 | String serialized = toJSON(grant); 26 | assertThat(serialized, is(notNullValue())); 27 | assertThat(serialized, JsonMatcher.hasEntry("user_id", "userId")); 28 | assertThat(serialized, JsonMatcher.hasEntry("clientID", "clientId")); 29 | assertThat(serialized, JsonMatcher.hasEntry("audience", "aud")); 30 | assertThat(serialized, JsonMatcher.hasEntry("scope", Arrays.asList("one", "two"))); 31 | } 32 | 33 | @Test 34 | public void shouldDeserialize() throws Exception { 35 | Grant grant = fromJSON(json, Grant.class); 36 | 37 | assertThat(grant, is(notNullValue())); 38 | assertThat(grant.getUserId(), is("userId")); 39 | assertThat(grant.getAudience(), is("aud")); 40 | assertThat(grant.getClientId(), is("clientId")); 41 | assertThat(grant.getScope(), contains("one", "two")); 42 | } 43 | 44 | @Test 45 | public void shouldIncludeReadOnlyValuesOnDeserialize() throws Exception { 46 | Grant grant = fromJSON(readOnlyJson, Grant.class); 47 | assertThat(grant, is(notNullValue())); 48 | 49 | assertThat(grant.getId(), is("grantId")); 50 | } 51 | } -------------------------------------------------------------------------------- /src/main/java/com/auth0/json/mgmt/guardian/Factor.java: -------------------------------------------------------------------------------- 1 | package com.auth0.json.mgmt.guardian; 2 | 3 | import com.fasterxml.jackson.annotation.JsonCreator; 4 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 5 | import com.fasterxml.jackson.annotation.JsonInclude; 6 | import com.fasterxml.jackson.annotation.JsonProperty; 7 | 8 | /** 9 | * Class that represents an Auth0 Guardian Factor object. Related to the {@link com.auth0.client.mgmt.GuardianEntity} entity. 10 | */ 11 | @SuppressWarnings({"unused", "WeakerAccess"}) 12 | @JsonIgnoreProperties(ignoreUnknown = true) 13 | @JsonInclude(JsonInclude.Include.NON_NULL) 14 | public class Factor { 15 | 16 | @JsonProperty("enabled") 17 | private Boolean enabled; 18 | @JsonProperty("trial_expired") 19 | private Boolean trialExpired; 20 | @JsonProperty("name") 21 | private String name; 22 | 23 | @JsonCreator 24 | Factor(@JsonProperty("enabled") Boolean enabled) { 25 | this.enabled = enabled; 26 | } 27 | 28 | /** 29 | * Whether this factor is enabled or not. 30 | * 31 | * @return true if this factor is enabled, false otherwise. 32 | */ 33 | @JsonProperty("enabled") 34 | public Boolean isEnabled() { 35 | return enabled; 36 | } 37 | 38 | /** 39 | * Sets whether this factor is enabled or not. 40 | * 41 | * @param enabled whether this factor is enabled or not. 42 | */ 43 | @JsonProperty("enabled") 44 | public void setEnabled(Boolean enabled) { 45 | this.enabled = enabled; 46 | } 47 | 48 | /** 49 | * Whether the trial has already expired or not. 50 | * 51 | * @return true if the trial has expired, false otherwise. 52 | */ 53 | @JsonProperty("trial_expired") 54 | public Boolean isTrialExpired() { 55 | return trialExpired; 56 | } 57 | 58 | /** 59 | * Getter for the name of this factor. 60 | * 61 | * @return the factor name. 62 | */ 63 | @JsonProperty("name") 64 | public String getName() { 65 | return name; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/test/java/com/auth0/json/mgmt/RuleTest.java: -------------------------------------------------------------------------------- 1 | package com.auth0.json.mgmt; 2 | 3 | import com.auth0.json.JsonMatcher; 4 | import com.auth0.json.JsonTest; 5 | import org.junit.Test; 6 | 7 | import static org.hamcrest.MatcherAssert.assertThat; 8 | import static org.hamcrest.Matchers.is; 9 | import static org.hamcrest.Matchers.notNullValue; 10 | 11 | public class RuleTest extends JsonTest { 12 | 13 | private static final String json = "{\"name\":\"my-rule\",\"script\":\"function(user,context,callback){}\",\"enabled\":true,\"order\":1}"; 14 | private static final String readOnlyJson = "{\"id\":\"ruleId\",\"stage\":\"login_success\"}"; 15 | 16 | @Test 17 | public void shouldSerialize() throws Exception { 18 | Rule rule = new Rule("my-rule", "function(user,context,callback){}"); 19 | rule.setOrder(1); 20 | rule.setEnabled(true); 21 | 22 | String serialized = toJSON(rule); 23 | assertThat(serialized, is(notNullValue())); 24 | assertThat(serialized, JsonMatcher.hasEntry("name", "my-rule")); 25 | assertThat(serialized, JsonMatcher.hasEntry("script", "function(user,context,callback){}")); 26 | assertThat(serialized, JsonMatcher.hasEntry("enabled", true)); 27 | assertThat(serialized, JsonMatcher.hasEntry("order", 1)); 28 | } 29 | 30 | @Test 31 | public void shouldDeserialize() throws Exception { 32 | Rule rule = fromJSON(json, Rule.class); 33 | 34 | assertThat(rule, is(notNullValue())); 35 | assertThat(rule.getName(), is("my-rule")); 36 | assertThat(rule.getScript(), is("function(user,context,callback){}")); 37 | assertThat(rule.getOrder(), is(1)); 38 | assertThat(rule.isEnabled(), is(true)); 39 | } 40 | 41 | @Test 42 | public void shouldIncludeReadOnlyValuesOnDeserialize() throws Exception { 43 | Rule rule = fromJSON(readOnlyJson, Rule.class); 44 | assertThat(rule, is(notNullValue())); 45 | 46 | assertThat(rule.getId(), is("ruleId")); 47 | assertThat(rule.getStage(), is("login_success")); 48 | } 49 | } -------------------------------------------------------------------------------- /src/main/java/com/auth0/client/mgmt/filter/ConnectionFilter.java: -------------------------------------------------------------------------------- 1 | package com.auth0.client.mgmt.filter; 2 | 3 | /** 4 | * Class used to filter the results received when calling the Connections endpoint. Related to the {@link com.auth0.client.mgmt.ConnectionsEntity} entity. 5 | */ 6 | public class ConnectionFilter extends FieldsFilter { 7 | 8 | /** 9 | * Filter by strategy 10 | * 11 | * @param strategy only retrieve items with this strategy. 12 | * @return this filter instance 13 | */ 14 | public ConnectionFilter withStrategy(String strategy) { 15 | parameters.put("strategy", strategy); 16 | return this; 17 | } 18 | 19 | /** 20 | * Filter by name 21 | * 22 | * @param name only retrieve the item with this name. 23 | * @return this filter instance 24 | */ 25 | public ConnectionFilter withName(String name) { 26 | parameters.put("name", name); 27 | return this; 28 | } 29 | 30 | /** 31 | * Filter by page 32 | * 33 | * @param pageNumber the page number to retrieve. 34 | * @param amountPerPage the amount of items per page to retrieve. 35 | * @return this filter instance 36 | */ 37 | public ConnectionFilter withPage(int pageNumber, int amountPerPage) { 38 | parameters.put("page", pageNumber); 39 | parameters.put("per_page", amountPerPage); 40 | return this; 41 | } 42 | 43 | /** 44 | * Include the query summary. 45 | * Warning: Can only be used with {@link com.auth0.client.mgmt.ConnectionsEntity#listAll(ConnectionFilter)} 46 | * 47 | * @param includeTotals whether to include or not the query summary. 48 | * @return this filter instance 49 | */ 50 | public ConnectionFilter withTotals(boolean includeTotals) { 51 | parameters.put("include_totals", includeTotals); 52 | return this; 53 | } 54 | 55 | @Override 56 | public ConnectionFilter withFields(String fields, boolean includeFields) { 57 | super.withFields(fields, includeFields); 58 | return this; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/main/java/com/auth0/client/mgmt/JobsEntity.java: -------------------------------------------------------------------------------- 1 | package com.auth0.client.mgmt; 2 | 3 | import com.auth0.json.mgmt.jobs.Job; 4 | import com.auth0.net.CustomRequest; 5 | import com.auth0.net.Request; 6 | import com.auth0.utils.Asserts; 7 | import com.fasterxml.jackson.core.type.TypeReference; 8 | import okhttp3.HttpUrl; 9 | import okhttp3.OkHttpClient; 10 | 11 | import java.util.HashMap; 12 | import java.util.Map; 13 | 14 | /** 15 | * Class that provides an implementation of the Jobs methods of the Management API as defined in https://auth0.com/docs/api/management/v2#!/Jobs 16 | */ 17 | @SuppressWarnings("WeakerAccess") 18 | public class JobsEntity extends BaseManagementEntity { 19 | 20 | JobsEntity(OkHttpClient client, HttpUrl baseUrl, String apiToken) { 21 | super(client, baseUrl, apiToken); 22 | } 23 | 24 | /** 25 | * Sends an Email Verification. A token with scope update:users is needed. 26 | * See https://auth0.com/docs/api/management/v2#!/Jobs/post_verification_email 27 | * 28 | * @param userId The user_id of the user to whom the email will be sent. 29 | * @param clientId The id of the client, if not provided the global one will be used. 30 | * @return a Request to execute. 31 | */ 32 | public Request sendVerificationEmail(String userId, String clientId) { 33 | Asserts.assertNotNull(userId, "user id"); 34 | 35 | String url = baseUrl 36 | .newBuilder() 37 | .addPathSegments("api/v2/jobs/verification-email") 38 | .build() 39 | .toString(); 40 | 41 | Map requestBody = new HashMap<>(); 42 | requestBody.put("user_id", userId); 43 | if (clientId != null && !clientId.isEmpty()) { 44 | requestBody.put("client_id", clientId); 45 | } 46 | 47 | CustomRequest request = new CustomRequest<>(client, url, "POST", new TypeReference() { 48 | }); 49 | request.addHeader("Authorization", "Bearer " + apiToken); 50 | request.setBody(requestBody); 51 | return request; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/test/java/com/auth0/client/mgmt/filter/GrantsFilterTest.java: -------------------------------------------------------------------------------- 1 | package com.auth0.client.mgmt.filter; 2 | 3 | import org.hamcrest.Matchers; 4 | import org.junit.Before; 5 | import org.junit.Test; 6 | 7 | import static org.hamcrest.CoreMatchers.is; 8 | import static org.hamcrest.CoreMatchers.notNullValue; 9 | import static org.junit.Assert.assertThat; 10 | 11 | public class GrantsFilterTest { 12 | 13 | private GrantsFilter filter; 14 | 15 | @Before 16 | public void setUp() throws Exception { 17 | filter = new GrantsFilter(); 18 | } 19 | 20 | @Test 21 | public void shouldFilterByAudience() throws Exception { 22 | GrantsFilter instance = filter.withAudience("https://myapi.auth0.com"); 23 | 24 | assertThat(filter, is(instance)); 25 | assertThat(filter.getAsMap(), is(notNullValue())); 26 | assertThat(filter.getAsMap(), Matchers.hasEntry("audience", (Object) "https://myapi.auth0.com")); 27 | } 28 | 29 | @Test 30 | public void shouldFilterByClientId() throws Exception { 31 | GrantsFilter instance = filter.withClientId("n3roinr32i23iron23nr"); 32 | 33 | assertThat(filter, is(instance)); 34 | assertThat(filter.getAsMap(), is(notNullValue())); 35 | assertThat(filter.getAsMap(), Matchers.hasEntry("client_id", (Object) "n3roinr32i23iron23nr")); 36 | } 37 | 38 | @Test 39 | public void shouldFilterByPage() throws Exception { 40 | GrantsFilter instance = filter.withPage(5, 10); 41 | 42 | assertThat(filter, is(instance)); 43 | assertThat(filter.getAsMap(), is(notNullValue())); 44 | assertThat(filter.getAsMap(), Matchers.hasEntry("per_page", (Object) 10)); 45 | assertThat(filter.getAsMap(), Matchers.hasEntry("page", (Object) 5)); 46 | } 47 | 48 | @Test 49 | public void shouldIncludeTotals() throws Exception { 50 | GrantsFilter instance = filter.withTotals(true); 51 | 52 | assertThat(filter, is(instance)); 53 | assertThat(filter.getAsMap(), is(notNullValue())); 54 | assertThat(filter.getAsMap(), Matchers.hasEntry("include_totals", (Object) true)); 55 | } 56 | 57 | } -------------------------------------------------------------------------------- /src/test/java/com/auth0/json/mgmt/client/JWTConfigurationTest.java: -------------------------------------------------------------------------------- 1 | package com.auth0.json.mgmt.client; 2 | 3 | import com.auth0.json.JsonMatcher; 4 | import com.auth0.json.JsonTest; 5 | import org.hamcrest.collection.IsMapContaining; 6 | import org.junit.Test; 7 | 8 | import java.util.Collections; 9 | import java.util.Map; 10 | 11 | import static org.hamcrest.MatcherAssert.assertThat; 12 | import static org.hamcrest.Matchers.is; 13 | import static org.hamcrest.Matchers.notNullValue; 14 | 15 | public class JWTConfigurationTest extends JsonTest { 16 | 17 | private static final String json = "{\"lifetime_in_seconds\":123,\"scopes\":{\"key\":\"value\"},\"alg\":\"alg\"}"; 18 | private static final String readOnlyJson = "{\"secret_encoded\":true}"; 19 | 20 | @Test 21 | public void shouldSerialize() throws Exception { 22 | JWTConfiguration config = new JWTConfiguration(123, Collections.singletonMap("key", "value"), "alg"); 23 | 24 | String serialized = toJSON(config); 25 | assertThat(serialized, is(notNullValue())); 26 | assertThat(serialized, JsonMatcher.hasEntry("lifetime_in_seconds", 123)); 27 | assertThat(serialized, JsonMatcher.hasEntry("scopes", Collections.singletonMap("key", "value"))); 28 | assertThat(serialized, JsonMatcher.hasEntry("alg", "alg")); 29 | } 30 | 31 | @Test 32 | public void shouldDeserialize() throws Exception { 33 | JWTConfiguration config = fromJSON(json, JWTConfiguration.class); 34 | 35 | assertThat(config, is(notNullValue())); 36 | 37 | assertThat(config.getAlgorithm(), is("alg")); 38 | assertThat(config.getLifetimeInSeconds(), is(123)); 39 | assertThat(config.getScopes(), is(notNullValue())); 40 | assertThat((Map) config.getScopes(), IsMapContaining.hasEntry("key", "value")); 41 | } 42 | 43 | @Test 44 | public void shouldIncludeReadOnlyValuesOnDeserialize() throws Exception { 45 | JWTConfiguration config = fromJSON(readOnlyJson, JWTConfiguration.class); 46 | assertThat(config, is(notNullValue())); 47 | 48 | assertThat(config.isSecretEncoded(), is(true)); 49 | } 50 | } -------------------------------------------------------------------------------- /src/test/java/com/auth0/client/mgmt/filter/ClientGrantsFilterTest.java: -------------------------------------------------------------------------------- 1 | package com.auth0.client.mgmt.filter; 2 | 3 | import org.hamcrest.Matchers; 4 | import org.junit.Before; 5 | import org.junit.Test; 6 | 7 | import static org.hamcrest.CoreMatchers.is; 8 | import static org.hamcrest.CoreMatchers.notNullValue; 9 | import static org.junit.Assert.assertThat; 10 | 11 | public class ClientGrantsFilterTest { 12 | 13 | private ClientGrantsFilter filter; 14 | 15 | @Before 16 | public void setUp() throws Exception { 17 | filter = new ClientGrantsFilter(); 18 | } 19 | 20 | @Test 21 | public void shouldFilterByAudience() throws Exception { 22 | ClientGrantsFilter instance = filter.withAudience("https://myapi.auth0.com"); 23 | 24 | assertThat(filter, is(instance)); 25 | assertThat(filter.getAsMap(), is(notNullValue())); 26 | assertThat(filter.getAsMap(), Matchers.hasEntry("audience", (Object) "https://myapi.auth0.com")); 27 | } 28 | 29 | @Test 30 | public void shouldFilterByClientId() throws Exception { 31 | ClientGrantsFilter instance = filter.withClientId("n3roinr32i23iron23nr"); 32 | 33 | assertThat(filter, is(instance)); 34 | assertThat(filter.getAsMap(), is(notNullValue())); 35 | assertThat(filter.getAsMap(), Matchers.hasEntry("client_id", (Object) "n3roinr32i23iron23nr")); 36 | } 37 | 38 | @Test 39 | public void shouldFilterByPage() throws Exception { 40 | ClientGrantsFilter instance = filter.withPage(5, 10); 41 | 42 | assertThat(filter, is(instance)); 43 | assertThat(filter.getAsMap(), is(notNullValue())); 44 | assertThat(filter.getAsMap(), Matchers.hasEntry("per_page", (Object) 10)); 45 | assertThat(filter.getAsMap(), Matchers.hasEntry("page", (Object) 5)); 46 | } 47 | 48 | @Test 49 | public void shouldIncludeTotals() throws Exception { 50 | ClientGrantsFilter instance = filter.withTotals(true); 51 | 52 | assertThat(filter, is(instance)); 53 | assertThat(filter.getAsMap(), is(notNullValue())); 54 | assertThat(filter.getAsMap(), Matchers.hasEntry("include_totals", (Object) true)); 55 | } 56 | 57 | } -------------------------------------------------------------------------------- /src/test/java/com/auth0/json/mgmt/emailproviders/EmailProviderTest.java: -------------------------------------------------------------------------------- 1 | package com.auth0.json.mgmt.emailproviders; 2 | 3 | import com.auth0.json.JsonMatcher; 4 | import com.auth0.json.JsonTest; 5 | import org.junit.Test; 6 | 7 | import java.util.Collections; 8 | 9 | import static org.hamcrest.MatcherAssert.assertThat; 10 | import static org.hamcrest.Matchers.is; 11 | import static org.hamcrest.Matchers.notNullValue; 12 | 13 | public class EmailProviderTest extends JsonTest { 14 | 15 | private static final String json = "{\"name\":\"provider\",\"enabled\":true,\"default_from_address\":\"https://google.com\",\"credentials\":{\"api_key\":\"key123\"},\"settings\":{}}"; 16 | 17 | @Test 18 | public void shouldSerialize() throws Exception { 19 | EmailProvider provider = new EmailProvider("provider"); 20 | provider.setEnabled(true); 21 | provider.setDefaultFromAddress("https://google.com"); 22 | provider.setSettings(Collections.emptyMap()); 23 | provider.setCredentials(new EmailProviderCredentials("key123")); 24 | 25 | String serialized = toJSON(provider); 26 | assertThat(serialized, is(notNullValue())); 27 | assertThat(serialized, JsonMatcher.hasEntry("name", "provider")); 28 | assertThat(serialized, JsonMatcher.hasEntry("enabled", true)); 29 | assertThat(serialized, JsonMatcher.hasEntry("default_from_address", "https://google.com")); 30 | assertThat(serialized, JsonMatcher.hasEntry("credentials", Collections.singletonMap("api_key", "key123"))); 31 | assertThat(serialized, JsonMatcher.hasEntry("settings", notNullValue())); 32 | } 33 | 34 | @Test 35 | public void shouldDeserialize() throws Exception { 36 | EmailProvider provider = fromJSON(json, EmailProvider.class); 37 | 38 | assertThat(provider, is(notNullValue())); 39 | assertThat(provider.getName(), is("provider")); 40 | assertThat(provider.isEnabled(), is(true)); 41 | assertThat(provider.getDefaultFromAddress(), is("https://google.com")); 42 | assertThat(provider.getSettings(), is(notNullValue())); 43 | assertThat(provider.getCredentials(), is(notNullValue())); 44 | } 45 | 46 | } -------------------------------------------------------------------------------- /src/main/java/com/auth0/json/auth/TokenHolder.java: -------------------------------------------------------------------------------- 1 | package com.auth0.json.auth; 2 | 3 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 4 | import com.fasterxml.jackson.annotation.JsonInclude; 5 | import com.fasterxml.jackson.annotation.JsonProperty; 6 | 7 | /** 8 | * Class that contains the Tokens obtained after a call to the {@link com.auth0.client.auth.AuthAPI} methods. 9 | */ 10 | @SuppressWarnings("unused") 11 | @JsonIgnoreProperties(ignoreUnknown = true) 12 | @JsonInclude(JsonInclude.Include.NON_NULL) 13 | public class TokenHolder { 14 | 15 | @JsonProperty("access_token") 16 | private String accessToken; 17 | @JsonProperty("id_token") 18 | private String idToken; 19 | @JsonProperty("refresh_token") 20 | private String refreshToken; 21 | @JsonProperty("token_type") 22 | private String tokenType; 23 | @JsonProperty("expires_in") 24 | private long expiresIn; 25 | 26 | /** 27 | * Getter for the Auth0's access token. 28 | * 29 | * @return the access token or null if missing. 30 | */ 31 | @JsonProperty("access_token") 32 | public String getAccessToken() { 33 | return accessToken; 34 | } 35 | 36 | /** 37 | * Getter for the Auth0's id token. 38 | * 39 | * @return the id token or null if missing. 40 | */ 41 | @JsonProperty("id_token") 42 | public String getIdToken() { 43 | return idToken; 44 | } 45 | 46 | /** 47 | * Getter for the Auth0's refresh token. 48 | * 49 | * @return the refresh token or null if missing. 50 | */ 51 | @JsonProperty("refresh_token") 52 | public String getRefreshToken() { 53 | return refreshToken; 54 | } 55 | 56 | /** 57 | * Getter for the token type. 58 | * 59 | * @return the token type or null if missing. 60 | */ 61 | @JsonProperty("token_type") 62 | public String getTokenType() { 63 | return tokenType; 64 | } 65 | 66 | /** 67 | * Getter for the expiration time ('exp' claim) of the recently issued token. 68 | * 69 | * @return the expiration time or null if missing. 70 | */ 71 | @JsonProperty("expires_in") 72 | public long getExpiresIn() { 73 | return expiresIn; 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /src/main/java/com/auth0/json/mgmt/client/IOS.java: -------------------------------------------------------------------------------- 1 | package com.auth0.json.mgmt.client; 2 | 3 | import com.fasterxml.jackson.annotation.JsonCreator; 4 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 5 | import com.fasterxml.jackson.annotation.JsonInclude; 6 | import com.fasterxml.jackson.annotation.JsonProperty; 7 | 8 | @SuppressWarnings({"WeakerAccess", "unused"}) 9 | @JsonIgnoreProperties(ignoreUnknown = true) 10 | @JsonInclude(JsonInclude.Include.NON_NULL) 11 | public class IOS { 12 | 13 | @JsonProperty("team_id") 14 | private String teamId; 15 | @JsonProperty("app_bundle_identifier") 16 | private String appBundleIdentifier; 17 | 18 | @JsonCreator 19 | public IOS(@JsonProperty("team_id") String teamId, @JsonProperty("app_bundle_identifier") String appBundleIdentifier) { 20 | this.teamId = teamId; 21 | this.appBundleIdentifier = appBundleIdentifier; 22 | } 23 | 24 | /** 25 | * Getter for the identifier assigned to the account that signs and upload the app to the store. 26 | * 27 | * @return the team identifier. 28 | */ 29 | @JsonProperty("team_id") 30 | public String getTeamId() { 31 | return teamId; 32 | } 33 | 34 | /** 35 | * Setter for the identifier assigned to the account that signs and upload the app to the store. 36 | * 37 | * @param teamId the team identifier to set. 38 | */ 39 | @JsonProperty("team_id") 40 | public void setTeamId(String teamId) { 41 | this.teamId = teamId; 42 | } 43 | 44 | /** 45 | * Getter for the unique identifier assigned by the developer to the app inside the store. 46 | * 47 | * @return the bundle identifier. 48 | */ 49 | @JsonProperty("app_bundle_identifier") 50 | public String getAppBundleIdentifier() { 51 | return appBundleIdentifier; 52 | } 53 | 54 | /** 55 | * Setter for the unique identifier assigned by the developer to the app inside the store. 56 | * 57 | * @param appBundleIdentifier the bundle identifier to set. 58 | */ 59 | @JsonProperty("app_bundle_identifier") 60 | public void setAppBundleIdentifier(String appBundleIdentifier) { 61 | this.appBundleIdentifier = appBundleIdentifier; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/test/java/com/auth0/json/mgmt/client/AddonsTest.java: -------------------------------------------------------------------------------- 1 | package com.auth0.json.mgmt.client; 2 | 3 | import com.auth0.json.JsonMatcher; 4 | import com.auth0.json.JsonTest; 5 | import org.junit.Test; 6 | 7 | import java.util.Collections; 8 | 9 | import static org.hamcrest.MatcherAssert.assertThat; 10 | import static org.hamcrest.Matchers.is; 11 | import static org.hamcrest.Matchers.notNullValue; 12 | 13 | public class AddonsTest extends JsonTest { 14 | 15 | private static final String json = "{\"rms\":{\"key\":\"value\"},\"mscrm\":{\"key\":\"value\"},\"slack\":{\"key\":\"value\"},\"layer\":{\"key\":\"value\"},\"other\":{\"key\":\"value\"}}"; 16 | 17 | @Test 18 | public void shouldSerialize() throws Exception { 19 | Addon addon = new Addon(); 20 | addon.setProperty("key", "value"); 21 | Addons addons = new Addons(addon, addon, addon, addon); 22 | addons.setAdditionalAddon("other", addon); 23 | 24 | String serialized = toJSON(addons); 25 | assertThat(serialized, is(notNullValue())); 26 | assertThat(serialized, JsonMatcher.hasEntry("rms", Collections.singletonMap("key", "value"))); 27 | assertThat(serialized, JsonMatcher.hasEntry("mscrm", Collections.singletonMap("key", "value"))); 28 | assertThat(serialized, JsonMatcher.hasEntry("slack", Collections.singletonMap("key", "value"))); 29 | assertThat(serialized, JsonMatcher.hasEntry("layer", Collections.singletonMap("key", "value"))); 30 | assertThat(serialized, JsonMatcher.hasEntry("other", Collections.singletonMap("key", "value"))); 31 | } 32 | 33 | @Test 34 | public void shouldDeserialize() throws Exception { 35 | Addons addons = fromJSON(json, Addons.class); 36 | 37 | assertThat(addons, is(notNullValue())); 38 | 39 | assertThat(addons.getRMS(), is(notNullValue())); 40 | assertThat(addons.getMSCRM(), is(notNullValue())); 41 | assertThat(addons.getSlack(), is(notNullValue())); 42 | assertThat(addons.getLayer(), is(notNullValue())); 43 | assertThat(addons.getAdditionalAddons(), is(notNullValue())); 44 | assertThat(addons.getAdditionalAddons().size(), is(1)); 45 | assertThat(addons.getAdditionalAddons().get("other"), is(notNullValue())); 46 | } 47 | } -------------------------------------------------------------------------------- /src/main/java/com/auth0/json/mgmt/users/ProfileData.java: -------------------------------------------------------------------------------- 1 | package com.auth0.json.mgmt.users; 2 | 3 | import com.fasterxml.jackson.annotation.*; 4 | 5 | import java.util.HashMap; 6 | import java.util.Map; 7 | 8 | @SuppressWarnings({"unused", "WeakerAccess"}) 9 | @JsonIgnoreProperties(ignoreUnknown = true) 10 | @JsonInclude(JsonInclude.Include.NON_NULL) 11 | public class ProfileData { 12 | 13 | @JsonProperty("email") 14 | private String email; 15 | @JsonProperty("email_verified") 16 | private Boolean emailVerified; 17 | @JsonProperty("name") 18 | private String name; 19 | @JsonProperty("username") 20 | private String username; 21 | @JsonProperty("given_name") 22 | private String givenName; 23 | @JsonProperty("phone_number") 24 | private String phoneNumber; 25 | @JsonProperty("phone_verified") 26 | private Boolean phoneVerified; 27 | @JsonProperty("family_name") 28 | private String familyName; 29 | private Map values; 30 | 31 | public ProfileData() { 32 | values = new HashMap<>(); 33 | } 34 | 35 | @JsonProperty("email") 36 | public String getEmail() { 37 | return email; 38 | } 39 | 40 | @JsonProperty("email_verified") 41 | public Boolean isEmailVerified() { 42 | return emailVerified; 43 | } 44 | 45 | @JsonProperty("name") 46 | public String getName() { 47 | return name; 48 | } 49 | 50 | @JsonProperty("username") 51 | public String getUsername() { 52 | return username; 53 | } 54 | 55 | @JsonProperty("given_name") 56 | public String getGivenName() { 57 | return givenName; 58 | } 59 | 60 | @JsonProperty("phone_number") 61 | public String getPhoneNumber() { 62 | return phoneNumber; 63 | } 64 | 65 | @JsonProperty("phone_verified") 66 | public Boolean isPhoneVerified() { 67 | return phoneVerified; 68 | } 69 | 70 | @JsonProperty("family_name") 71 | public String getFamilyName() { 72 | return familyName; 73 | } 74 | 75 | @JsonAnySetter 76 | void setValue(String key, Object value) { 77 | values.put(key, value); 78 | } 79 | 80 | @JsonAnyGetter 81 | public Map getValues() { 82 | return values; 83 | } 84 | } -------------------------------------------------------------------------------- /src/main/java/com/auth0/json/mgmt/client/Addons.java: -------------------------------------------------------------------------------- 1 | package com.auth0.json.mgmt.client; 2 | 3 | import com.fasterxml.jackson.annotation.*; 4 | 5 | import java.util.HashMap; 6 | import java.util.Map; 7 | 8 | @SuppressWarnings({"WeakerAccess", "unused"}) 9 | @JsonIgnoreProperties(ignoreUnknown = true) 10 | @JsonInclude(JsonInclude.Include.NON_NULL) 11 | public class Addons { 12 | 13 | @JsonProperty("rms") 14 | private Addon rms; 15 | @JsonProperty("mscrm") 16 | private Addon mscrm; 17 | @JsonProperty("slack") 18 | private Addon slack; 19 | @JsonProperty("layer") 20 | private Addon layer; 21 | 22 | @JsonUnwrapped 23 | @JsonIgnore 24 | private Map additionalAddons; 25 | 26 | @JsonCreator 27 | public Addons(@JsonProperty("rms") Addon rms, @JsonProperty("mscrm") Addon mscrm, @JsonProperty("slack") Addon slack, @JsonProperty("layer") Addon layer) { 28 | this.additionalAddons = new HashMap<>(); 29 | this.rms = rms; 30 | this.mscrm = mscrm; 31 | this.slack = slack; 32 | this.layer = layer; 33 | } 34 | 35 | @JsonProperty("rms") 36 | public Addon getRMS() { 37 | return rms; 38 | } 39 | 40 | @JsonProperty("rms") 41 | public void setRMS(Addon rms) { 42 | this.rms = rms; 43 | } 44 | 45 | @JsonProperty("mscrm") 46 | public Addon getMSCRM() { 47 | return mscrm; 48 | } 49 | 50 | @JsonProperty("mscrm") 51 | public void setMSCRM(Addon mscrm) { 52 | this.mscrm = mscrm; 53 | } 54 | 55 | @JsonProperty("slack") 56 | public Addon getSlack() { 57 | return slack; 58 | } 59 | 60 | @JsonProperty("slack") 61 | public void setSlack(Addon slack) { 62 | this.slack = slack; 63 | } 64 | 65 | @JsonProperty("layer") 66 | public Addon getLayer() { 67 | return layer; 68 | } 69 | 70 | @JsonProperty("layer") 71 | public void setLayer(Addon layer) { 72 | this.layer = layer; 73 | } 74 | 75 | @JsonAnyGetter 76 | public Map getAdditionalAddons() { 77 | return additionalAddons; 78 | } 79 | 80 | @JsonAnySetter 81 | public void setAdditionalAddon(String name, Addon addon) { 82 | this.additionalAddons.put(name, addon); 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /src/test/java/com/auth0/json/mgmt/guardian/EnrollmentTicketTest.java: -------------------------------------------------------------------------------- 1 | package com.auth0.json.mgmt.guardian; 2 | 3 | import com.auth0.json.JsonMatcher; 4 | import com.auth0.json.JsonTest; 5 | import org.junit.Test; 6 | 7 | import static org.hamcrest.MatcherAssert.assertThat; 8 | import static org.hamcrest.Matchers.is; 9 | import static org.hamcrest.Matchers.notNullValue; 10 | 11 | public class EnrollmentTicketTest extends JsonTest { 12 | 13 | private static final String readOnlyJson = "{\"ticket_id\":\"ticket123\",\"ticket_url\":\"https://auth0.com/guardian/tickets/123\"}"; 14 | 15 | @Test 16 | public void shouldSerializeDataToBeSent() throws Exception { 17 | EnrollmentTicket ticket = new EnrollmentTicket("1", true, "me@auth0.com"); 18 | 19 | String serialized = toJSON(ticket); 20 | assertThat(serialized, is(notNullValue())); 21 | assertThat(serialized, JsonMatcher.hasEntry("user_id", "1")); 22 | assertThat(serialized, JsonMatcher.hasEntry("send_mail", true)); 23 | assertThat(serialized, JsonMatcher.hasEntry("email", "me@auth0.com")); 24 | } 25 | 26 | @Test 27 | public void shouldSerializeDataToBeSentOnlyUserId() throws Exception { 28 | EnrollmentTicket ticket = new EnrollmentTicket("1"); 29 | 30 | String serialized = toJSON(ticket); 31 | assertThat(serialized, is(notNullValue())); 32 | assertThat(serialized, JsonMatcher.hasEntry("user_id", "1")); 33 | } 34 | 35 | @Test 36 | public void shouldSerializeDataToBeSentOnlyUserIdAndSendEmail() throws Exception { 37 | EnrollmentTicket ticket = new EnrollmentTicket("1", true); 38 | 39 | String serialized = toJSON(ticket); 40 | assertThat(serialized, is(notNullValue())); 41 | assertThat(serialized, JsonMatcher.hasEntry("user_id", "1")); 42 | assertThat(serialized, JsonMatcher.hasEntry("send_mail", true)); 43 | } 44 | 45 | @Test 46 | public void shouldIncludeReadOnlyValuesOnDeserialize() throws Exception { 47 | EnrollmentTicket ticket = fromJSON(readOnlyJson, EnrollmentTicket.class); 48 | assertThat(ticket, is(notNullValue())); 49 | 50 | assertThat(ticket.getTicketId(), is("ticket123")); 51 | assertThat(ticket.getTicketUrl(), is("https://auth0.com/guardian/tickets/123")); 52 | } 53 | } -------------------------------------------------------------------------------- /src/test/java/com/auth0/json/mgmt/DeviceCredentialsTest.java: -------------------------------------------------------------------------------- 1 | package com.auth0.json.mgmt; 2 | 3 | import com.auth0.json.JsonMatcher; 4 | import com.auth0.json.JsonTest; 5 | import org.junit.Test; 6 | 7 | import static org.hamcrest.MatcherAssert.assertThat; 8 | import static org.hamcrest.Matchers.is; 9 | import static org.hamcrest.Matchers.notNullValue; 10 | 11 | public class DeviceCredentialsTest extends JsonTest { 12 | 13 | private static final String json = "{\"device_name\":\"devName\",\"type\":\"publicKey\",\"device_id\":\"dev123\",\"user_id\":\"theUserId\"}"; 14 | private static final String readOnlyJson = "{\"id\":\"credentialsId\"}"; 15 | 16 | @Test 17 | public void shouldSerialize() throws Exception { 18 | DeviceCredentials credentials = new DeviceCredentials("devName", "publicKey", "val123", "dev123", "client123"); 19 | credentials.setUserId("theUserId"); 20 | 21 | String serialized = toJSON(credentials); 22 | assertThat(serialized, is(notNullValue())); 23 | assertThat(serialized, JsonMatcher.hasEntry("device_name", "devName")); 24 | assertThat(serialized, JsonMatcher.hasEntry("type", "publicKey")); 25 | assertThat(serialized, JsonMatcher.hasEntry("value", "val123")); 26 | assertThat(serialized, JsonMatcher.hasEntry("device_id", "dev123")); 27 | assertThat(serialized, JsonMatcher.hasEntry("client_id", "client123")); 28 | assertThat(serialized, JsonMatcher.hasEntry("user_id", "theUserId")); 29 | } 30 | 31 | @Test 32 | public void shouldDeserialize() throws Exception { 33 | DeviceCredentials credentials = fromJSON(json, DeviceCredentials.class); 34 | 35 | assertThat(credentials, is(notNullValue())); 36 | assertThat(credentials.getDeviceName(), is("devName")); 37 | assertThat(credentials.getType(), is("publicKey")); 38 | assertThat(credentials.getDeviceId(), is("dev123")); 39 | assertThat(credentials.getUserId(), is("theUserId")); 40 | } 41 | 42 | @Test 43 | public void shouldIncludeReadOnlyValuesOnDeserialize() throws Exception { 44 | DeviceCredentials credentials = fromJSON(readOnlyJson, DeviceCredentials.class); 45 | assertThat(credentials, is(notNullValue())); 46 | 47 | assertThat(credentials.getId(), is("credentialsId")); 48 | } 49 | } -------------------------------------------------------------------------------- /src/main/java/com/auth0/json/mgmt/client/Android.java: -------------------------------------------------------------------------------- 1 | package com.auth0.json.mgmt.client; 2 | 3 | import com.fasterxml.jackson.annotation.JsonCreator; 4 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 5 | import com.fasterxml.jackson.annotation.JsonInclude; 6 | import com.fasterxml.jackson.annotation.JsonProperty; 7 | 8 | import java.util.List; 9 | 10 | 11 | @SuppressWarnings({"WeakerAccess", "unused"}) 12 | @JsonIgnoreProperties(ignoreUnknown = true) 13 | @JsonInclude(JsonInclude.Include.NON_NULL) 14 | public class Android { 15 | 16 | @JsonProperty("app_package_name") 17 | private String appPackageName; 18 | @JsonProperty("sha256_cert_fingerprints") 19 | private List sha256CertFingerprints; 20 | 21 | @JsonCreator 22 | public Android(@JsonProperty("app_package_name") String appPackageName, @JsonProperty("sha256_cert_fingerprints") List sha256CertFingerprints) { 23 | this.appPackageName = appPackageName; 24 | this.sha256CertFingerprints = sha256CertFingerprints; 25 | } 26 | 27 | /** 28 | * Getter for the Application Package Name, found in the AndroidManifest.xml file. 29 | * 30 | * @return the package name. 31 | */ 32 | @JsonProperty("app_package_name") 33 | public String getAppPackageName() { 34 | return appPackageName; 35 | } 36 | 37 | /** 38 | * Setter for the Application Package Name. 39 | * 40 | * @param appPackageName the package name to set. 41 | */ 42 | @JsonProperty("app_package_name") 43 | public void setAppPackageName(String appPackageName) { 44 | this.appPackageName = appPackageName; 45 | } 46 | 47 | /** 48 | * Getter for the list of allowed SHA256 certificate fingerprints. 49 | * 50 | * @return the list of allowed fingerprints. 51 | */ 52 | @JsonProperty("sha256_cert_fingerprints") 53 | public List getSHA256CertFingerprints() { 54 | return sha256CertFingerprints; 55 | } 56 | 57 | /** 58 | * Setter for the list of allowed SHA256 certificate fingerprints. 59 | * 60 | * @param certFingerprints the list of allowed fingerprints to set. 61 | */ 62 | @JsonProperty("sha256_cert_fingerprints") 63 | public void setSHA256CertFingerprints(List certFingerprints) { 64 | this.sha256CertFingerprints = certFingerprints; 65 | } 66 | } -------------------------------------------------------------------------------- /src/test/java/com/auth0/net/CreateUserRequestTest.java: -------------------------------------------------------------------------------- 1 | package com.auth0.net; 2 | 3 | import com.auth0.client.MockServer; 4 | import com.auth0.json.auth.CreatedUser; 5 | import okhttp3.OkHttpClient; 6 | import okhttp3.mockwebserver.RecordedRequest; 7 | import org.junit.Before; 8 | import org.junit.Test; 9 | 10 | import java.util.HashMap; 11 | import java.util.Map; 12 | 13 | import static com.auth0.client.MockServer.*; 14 | import static org.hamcrest.Matchers.*; 15 | import static org.junit.Assert.assertThat; 16 | 17 | public class CreateUserRequestTest { 18 | 19 | private OkHttpClient client; 20 | private MockServer server; 21 | 22 | @Before 23 | public void setUp() throws Exception { 24 | client = new OkHttpClient(); 25 | server = new MockServer(); 26 | } 27 | 28 | @Test 29 | public void shouldCreatePOSTRequest() throws Exception { 30 | CreateUserRequest request = new CreateUserRequest(client, server.getBaseUrl()); 31 | assertThat(request, is(notNullValue())); 32 | request.addParameter("non_empty", "body"); 33 | 34 | server.jsonResponse(AUTH_SIGN_UP, 200); 35 | CreatedUser execute = request.execute(); 36 | RecordedRequest recordedRequest = server.takeRequest(); 37 | assertThat(recordedRequest.getMethod(), is("POST")); 38 | assertThat(execute, is(notNullValue())); 39 | } 40 | 41 | @Test 42 | public void shouldSetSignUpCustomFields() throws Exception { 43 | CreateUserRequest request = new CreateUserRequest(client, server.getBaseUrl()); 44 | assertThat(request, is(notNullValue())); 45 | Map customFields = new HashMap<>(); 46 | customFields.put("name", "john"); 47 | customFields.put("age", "25"); 48 | request.setCustomFields(customFields); 49 | 50 | server.jsonResponse(AUTH_TOKENS, 200); 51 | request.execute(); 52 | RecordedRequest recordedRequest = server.takeRequest(); 53 | 54 | Map values = bodyFromRequest(recordedRequest); 55 | assertThat(values, is(notNullValue())); 56 | assertThat(values, hasKey("user_metadata")); 57 | Map fields = (Map) values.get("user_metadata"); 58 | assertThat(fields, hasEntry("name", "john")); 59 | assertThat(fields, hasEntry("age", "25")); 60 | } 61 | 62 | 63 | } -------------------------------------------------------------------------------- /src/main/java/com/auth0/json/mgmt/Page.java: -------------------------------------------------------------------------------- 1 | package com.auth0.json.mgmt; 2 | 3 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 4 | import com.fasterxml.jackson.annotation.JsonInclude; 5 | import com.fasterxml.jackson.annotation.JsonProperty; 6 | 7 | import java.util.List; 8 | 9 | /** 10 | * Class that represents a paginated list of objects. 11 | * 12 | * @param the type of the object this page contains. 13 | */ 14 | @SuppressWarnings("unused") 15 | @JsonIgnoreProperties(ignoreUnknown = true) 16 | @JsonInclude(JsonInclude.Include.NON_NULL) 17 | public abstract class Page { 18 | 19 | @JsonProperty("start") 20 | private Integer start; 21 | @JsonProperty("length") 22 | private Integer length; 23 | @JsonProperty("total") 24 | private Integer total; 25 | @JsonProperty("limit") 26 | private Integer limit; 27 | private List items; 28 | 29 | public Page(List items) { 30 | this.items = items; 31 | } 32 | 33 | public Page(Integer start, Integer length, Integer total, Integer limit, List items) { 34 | this.start = start; 35 | this.length = length; 36 | this.total = total; 37 | this.limit = limit; 38 | this.items = items; 39 | } 40 | 41 | /** 42 | * Getter for the position of the item this page starts from. 43 | * 44 | * @return the start value. 45 | */ 46 | @JsonProperty("start") 47 | public Integer getStart() { 48 | return start; 49 | } 50 | 51 | /** 52 | * Getter for the amount of items per page. 53 | * 54 | * @return the length value. 55 | */ 56 | @JsonProperty("length") 57 | public Integer getLength() { 58 | return length; 59 | } 60 | 61 | /** 62 | * Getter for the total amount of items. 63 | * 64 | * @return the total value. 65 | */ 66 | @JsonProperty("total") 67 | public Integer getTotal() { 68 | return total; 69 | } 70 | 71 | /** 72 | * Getter for the items amount limit. 73 | * 74 | * @return the limit value. 75 | */ 76 | @JsonProperty("limit") 77 | public Integer getLimit() { 78 | return limit; 79 | } 80 | 81 | /** 82 | * Getter for the list of items. 83 | * 84 | * @return the list of items. 85 | */ 86 | public List getItems() { 87 | return items; 88 | } 89 | } -------------------------------------------------------------------------------- /src/main/java/com/auth0/json/mgmt/PageDeserializer.java: -------------------------------------------------------------------------------- 1 | package com.auth0.json.mgmt; 2 | 3 | import com.fasterxml.jackson.core.JsonParser; 4 | import com.fasterxml.jackson.databind.DeserializationContext; 5 | import com.fasterxml.jackson.databind.JsonNode; 6 | import com.fasterxml.jackson.databind.ObjectMapper; 7 | import com.fasterxml.jackson.databind.deser.std.StdDeserializer; 8 | import com.fasterxml.jackson.databind.node.ArrayNode; 9 | import com.fasterxml.jackson.databind.type.CollectionType; 10 | 11 | import java.io.IOException; 12 | import java.util.List; 13 | 14 | public abstract class PageDeserializer extends StdDeserializer { 15 | 16 | private String itemsPropertyName; 17 | private Class uClazz; 18 | 19 | protected PageDeserializer(Class clazz, String arrayName) { 20 | super(Object.class); 21 | this.uClazz = clazz; 22 | this.itemsPropertyName = arrayName; 23 | } 24 | 25 | @Override 26 | public T deserialize(JsonParser p, DeserializationContext ctx) throws IOException { 27 | JsonNode node = p.getCodec().readTree(p); 28 | ObjectMapper mapper = new ObjectMapper(); 29 | if (node.isArray()) { 30 | return createPage(getArrayElements((ArrayNode) node, mapper)); 31 | } 32 | 33 | Integer start = getIntegerValue(node.get("start")); 34 | Integer length = getIntegerValue(node.get("length")); 35 | Integer total = getIntegerValue(node.get("total")); 36 | Integer limit = getIntegerValue(node.get("limit")); 37 | ArrayNode array = (ArrayNode) node.get(itemsPropertyName); 38 | 39 | return createPage(start, length, total, limit, getArrayElements(array, mapper)); 40 | } 41 | 42 | protected abstract T createPage(List items); 43 | 44 | protected abstract T createPage(Integer start, Integer length, Integer total, Integer limit, List items); 45 | 46 | private Integer getIntegerValue(JsonNode node) { 47 | if (node == null || node.isNull()) { 48 | return null; 49 | } else { 50 | return node.intValue(); 51 | } 52 | } 53 | 54 | private List getArrayElements(ArrayNode array, ObjectMapper mapper) throws IOException { 55 | CollectionType type = mapper.getTypeFactory().constructCollectionType(List.class, uClazz); 56 | return mapper.readerFor(type).readValue(array); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/com/auth0/json/mgmt/tickets/EmailVerificationTicket.java: -------------------------------------------------------------------------------- 1 | 2 | package com.auth0.json.mgmt.tickets; 3 | 4 | import com.fasterxml.jackson.annotation.JsonCreator; 5 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 6 | import com.fasterxml.jackson.annotation.JsonInclude; 7 | import com.fasterxml.jackson.annotation.JsonProperty; 8 | 9 | /** 10 | * Class that represents an Auth0 Email Verification Ticket object. Related to the {@link com.auth0.client.mgmt.TicketsEntity} entity. 11 | */ 12 | @SuppressWarnings({"unused", "WeakerAccess", "FieldCanBeLocal"}) 13 | @JsonIgnoreProperties(ignoreUnknown = true) 14 | @JsonInclude(JsonInclude.Include.NON_NULL) 15 | public class EmailVerificationTicket { 16 | 17 | @JsonProperty("user_id") 18 | private String userId; 19 | @JsonProperty("result_url") 20 | private String resultUrl; 21 | @JsonProperty("ttl_sec") 22 | private Integer ttlSec; 23 | @JsonProperty("ticket") 24 | private String ticket; 25 | 26 | @JsonCreator 27 | public EmailVerificationTicket(@JsonProperty("user_id") String userId) { 28 | this.userId = userId; 29 | } 30 | 31 | /** 32 | * Setter for the id of the user this ticket is meant to. 33 | * 34 | * @param userId the user id to set. 35 | */ 36 | @JsonProperty("user_id") 37 | public void setUserId(String userId) { 38 | this.userId = userId; 39 | } 40 | 41 | /** 42 | * Setter for the url the user will be redirected to after using the ticket. 43 | * 44 | * @param resultUrl the result url. 45 | */ 46 | @JsonProperty("result_url") 47 | public void setResultUrl(String resultUrl) { 48 | this.resultUrl = resultUrl; 49 | } 50 | 51 | /** 52 | * The ticket's lifetime in seconds starting from the moment of creation. After expiration the ticket can not be used to verify the users's email. If not specified or if you send 0 the Auth0 default lifetime will be applied. 53 | * 54 | * @param seconds the lifetime in seconds to set. 55 | */ 56 | @JsonProperty("ttl_sec") 57 | public void setTTLSeconds(Integer seconds) { 58 | this.ttlSec = seconds; 59 | } 60 | 61 | /** 62 | * Getter for the ticket url. 63 | * 64 | * @return the ticket url. 65 | */ 66 | @JsonProperty("ticket") 67 | public String getTicket() { 68 | return ticket; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/main/java/com/auth0/client/mgmt/filter/ClientFilter.java: -------------------------------------------------------------------------------- 1 | package com.auth0.client.mgmt.filter; 2 | 3 | /** 4 | * Class used to filter the results received when calling the Clients endpoint. Related to the {@link com.auth0.client.mgmt.ClientsEntity} entity. 5 | */ 6 | public class ClientFilter extends FieldsFilter { 7 | 8 | /** 9 | * Include the query summary 10 | * 11 | * @param includeTotals whether to include or not the query summary. 12 | * @return this filter instance 13 | */ 14 | public ClientFilter withTotals(boolean includeTotals) { 15 | parameters.put("include_totals", includeTotals); 16 | return this; 17 | } 18 | 19 | /** 20 | * Filter by page 21 | * 22 | * @param pageNumber the page number to retrieve. 23 | * @param amountPerPage the amount of items per page to retrieve. 24 | * @return this filter instance 25 | */ 26 | public ClientFilter withPage(int pageNumber, int amountPerPage) { 27 | parameters.put("page", pageNumber); 28 | parameters.put("per_page", amountPerPage); 29 | return this; 30 | } 31 | 32 | /** 33 | * Filter by global clients 34 | * 35 | * @param isGlobal whether the client should or not be global 36 | * @return this filter instance 37 | */ 38 | public ClientFilter withIsGlobal(boolean isGlobal) { 39 | parameters.put("is_global", isGlobal); 40 | return this; 41 | } 42 | 43 | /** 44 | * Filter by first party clients 45 | * 46 | * @param isFirstParty whether the client should or not be first party 47 | * @return this filter instance 48 | */ 49 | public ClientFilter withIsFirstParty(boolean isFirstParty) { 50 | parameters.put("is_first_party", isFirstParty); 51 | return this; 52 | } 53 | 54 | /** 55 | * Filter by application type 56 | * 57 | * @param appType A comma separated list of application types used to filter the returned clients (native, spa, regular_web, non_interactive) 58 | * @return this filter instance 59 | */ 60 | public ClientFilter withAppType(String appType) { 61 | parameters.put("app_type", appType); 62 | return this; 63 | } 64 | 65 | @Override 66 | public ClientFilter withFields(String fields, boolean includeFields) { 67 | super.withFields(fields, includeFields); 68 | return this; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/test/java/com/auth0/json/auth/UserInfoTest.java: -------------------------------------------------------------------------------- 1 | package com.auth0.json.auth; 2 | 3 | import com.auth0.json.JsonMatcher; 4 | import com.auth0.json.JsonTest; 5 | import org.hamcrest.collection.IsMapContaining; 6 | import org.junit.Test; 7 | 8 | import static org.hamcrest.MatcherAssert.assertThat; 9 | import static org.hamcrest.Matchers.is; 10 | import static org.hamcrest.Matchers.notNullValue; 11 | 12 | public class UserInfoTest extends JsonTest { 13 | 14 | private static final String json = "{\"email_verified\":false,\"client_id\":\"q2hnj2iu...\",\"updated_at\":\"2016-12-05T15:15:40.545Z\",\"name\":\"test.account@userinfo.com\",\"email\":\"test.account@userinfo.com\"}"; 15 | 16 | @Test 17 | public void shouldSerialize() throws Exception { 18 | UserInfo info = new UserInfo(); 19 | info.setValue("email_verified", false); 20 | info.setValue("email", "test.account@userinfo.com"); 21 | info.setValue("client_id", "q2hnj2iu..."); 22 | info.setValue("updated_at", "2016-12-05T15:15:40.545Z"); 23 | info.setValue("name", "test.account@userinfo.com"); 24 | 25 | String serialized = toJSON(info); 26 | assertThat(serialized, is(notNullValue())); 27 | assertThat(serialized, JsonMatcher.hasEntry("email_verified", false)); 28 | assertThat(serialized, JsonMatcher.hasEntry("email", "test.account@userinfo.com")); 29 | assertThat(serialized, JsonMatcher.hasEntry("client_id", "q2hnj2iu...")); 30 | assertThat(serialized, JsonMatcher.hasEntry("updated_at", "2016-12-05T15:15:40.545Z")); 31 | assertThat(serialized, JsonMatcher.hasEntry("name", "test.account@userinfo.com")); 32 | } 33 | 34 | @Test 35 | public void shouldDeserialize() throws Exception { 36 | UserInfo info = fromJSON(json, UserInfo.class); 37 | 38 | assertThat(info, is(notNullValue())); 39 | 40 | assertThat(info.getValues(), IsMapContaining.hasEntry("email_verified", (Object) false)); 41 | assertThat(info.getValues(), IsMapContaining.hasEntry("email", (Object) "test.account@userinfo.com")); 42 | assertThat(info.getValues(), IsMapContaining.hasEntry("client_id", (Object) "q2hnj2iu...")); 43 | assertThat(info.getValues(), IsMapContaining.hasEntry("updated_at", (Object) "2016-12-05T15:15:40.545Z")); 44 | assertThat(info.getValues(), IsMapContaining.hasEntry("name", (Object) "test.account@userinfo.com")); 45 | } 46 | } -------------------------------------------------------------------------------- /src/main/java/com/auth0/json/mgmt/client/SigningKey.java: -------------------------------------------------------------------------------- 1 | package com.auth0.json.mgmt.client; 2 | 3 | import com.fasterxml.jackson.annotation.JsonCreator; 4 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 5 | import com.fasterxml.jackson.annotation.JsonInclude; 6 | import com.fasterxml.jackson.annotation.JsonProperty; 7 | 8 | @SuppressWarnings({"WeakerAccess", "unused"}) 9 | @JsonIgnoreProperties(ignoreUnknown = true) 10 | @JsonInclude(JsonInclude.Include.NON_NULL) 11 | public class SigningKey { 12 | 13 | @JsonProperty("cert") 14 | private String cert; 15 | @JsonProperty("pkcs7") 16 | private String pkcs7; 17 | @JsonProperty("subject") 18 | private String subject; 19 | 20 | @JsonCreator 21 | public SigningKey(@JsonProperty("cert") String cert, @JsonProperty("pkcs7") String pkcs7, @JsonProperty("subject") String subject) { 22 | this.cert = cert; 23 | this.pkcs7 = pkcs7; 24 | this.subject = subject; 25 | } 26 | 27 | /** 28 | * Getter for the signing public key. 29 | * 30 | * @return the public key. 31 | */ 32 | @JsonProperty("cert") 33 | public String getCert() { 34 | return cert; 35 | } 36 | 37 | /** 38 | * Setter for the signing public key. 39 | * 40 | * @param cert the certificate to set. 41 | */ 42 | @JsonProperty("cert") 43 | public void setCert(String cert) { 44 | this.cert = cert; 45 | } 46 | 47 | /** 48 | * Getter for the signing public key in PKCS#7 format. 49 | * 50 | * @return the public key in PKCS#7 format. 51 | */ 52 | @JsonProperty("pkcs7") 53 | public String getPKCS7() { 54 | return pkcs7; 55 | } 56 | 57 | /** 58 | * Setter for the signing public key in PKCS#7 format. 59 | * 60 | * @param pkcs7 the public key in PKCS#7 format to use. 61 | */ 62 | @JsonProperty("pkcs7") 63 | public void setPKCS7(String pkcs7) { 64 | this.pkcs7 = pkcs7; 65 | } 66 | 67 | /** 68 | * Getter for the subject. 69 | * 70 | * @return the subject. 71 | */ 72 | @JsonProperty("subject") 73 | public String getSubject() { 74 | return subject; 75 | } 76 | 77 | /** 78 | * Setter for the subject. 79 | * 80 | * @param subject the subject to set. 81 | */ 82 | @JsonProperty("subject") 83 | public void setSubject(String subject) { 84 | this.subject = subject; 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /src/test/resources/auth/password_strength_error_some.json: -------------------------------------------------------------------------------- 1 | { 2 | "code": "invalid_password", 3 | "description": { 4 | "rules": [ 5 | { 6 | "code": "lengthAtLeast", 7 | "format": [ 8 | 10 9 | ], 10 | "message": "At least %d characters in length", 11 | "verified": true 12 | }, 13 | { 14 | "code": "containsAtLeast", 15 | "format": [ 16 | 3, 17 | 4 18 | ], 19 | "items": [ 20 | { 21 | "code": "lowerCase", 22 | "message": "lower case letters (a-z)", 23 | "verified": true 24 | }, 25 | { 26 | "code": "upperCase", 27 | "message": "upper case letters (A-Z)", 28 | "verified": true 29 | }, 30 | { 31 | "code": "numbers", 32 | "message": "numbers (i.e. 0-9)", 33 | "verified": true 34 | }, 35 | { 36 | "code": "specialCharacters", 37 | "message": "special characters (e.g. !@#$%^&*)", 38 | "verified": false 39 | } 40 | ], 41 | "message": "Contain at least %d of the following %d types of characters:", 42 | "verified": true 43 | }, 44 | { 45 | "code": "shouldContain", 46 | "items": [ 47 | { 48 | "code": "lowerCase", 49 | "message": "lower case letters (a-z)", 50 | "verified": false 51 | }, 52 | { 53 | "code": "upperCase", 54 | "message": "upper case letters (A-Z)", 55 | "verified": false 56 | }, 57 | { 58 | "code": "numbers", 59 | "message": "numbers (i.e. 0-9)", 60 | "verified": false 61 | }, 62 | { 63 | "code": "specialCharacters", 64 | "message": "special characters (e.g. !@#$%^&*)", 65 | "verified": false 66 | } 67 | ], 68 | "message": "Should contain:", 69 | "verified": false 70 | }, 71 | { 72 | "code": "identicalChars", 73 | "format": [ 74 | 2, 75 | "aaa" 76 | ], 77 | "message": "No more than %d identical characters in a row (e.g., \"%s\" not allowed)", 78 | "verified": true 79 | } 80 | ], 81 | "verified": false 82 | }, 83 | "name": "PasswordStrengthError", 84 | "statusCode": 400 85 | } -------------------------------------------------------------------------------- /src/test/resources/auth/password_strength_error_none.json: -------------------------------------------------------------------------------- 1 | { 2 | "code": "invalid_password", 3 | "description": { 4 | "rules": [ 5 | { 6 | "code": "lengthAtLeast", 7 | "format": [ 8 | 10 9 | ], 10 | "message": "At least %d characters in length", 11 | "verified": false 12 | }, 13 | { 14 | "code": "containsAtLeast", 15 | "format": [ 16 | 3, 17 | 4 18 | ], 19 | "items": [ 20 | { 21 | "code": "lowerCase", 22 | "message": "lower case letters (a-z)", 23 | "verified": false 24 | }, 25 | { 26 | "code": "upperCase", 27 | "message": "upper case letters (A-Z)", 28 | "verified": false 29 | }, 30 | { 31 | "code": "numbers", 32 | "message": "numbers (i.e. 0-9)", 33 | "verified": false 34 | }, 35 | { 36 | "code": "specialCharacters", 37 | "message": "special characters (e.g. !@#$%^&*)", 38 | "verified": false 39 | } 40 | ], 41 | "message": "Contain at least %d of the following %d types of characters:", 42 | "verified": false 43 | }, 44 | { 45 | "code": "shouldContain", 46 | "items": [ 47 | { 48 | "code": "lowerCase", 49 | "message": "lower case letters (a-z)", 50 | "verified": false 51 | }, 52 | { 53 | "code": "upperCase", 54 | "message": "upper case letters (A-Z)", 55 | "verified": false 56 | }, 57 | { 58 | "code": "numbers", 59 | "message": "numbers (i.e. 0-9)", 60 | "verified": false 61 | }, 62 | { 63 | "code": "specialCharacters", 64 | "message": "special characters (e.g. !@#$%^&*)", 65 | "verified": false 66 | } 67 | ], 68 | "message": "Should contain:", 69 | "verified": false 70 | }, 71 | { 72 | "code": "identicalChars", 73 | "format": [ 74 | 2, 75 | "aaa" 76 | ], 77 | "message": "No more than %d identical characters in a row (e.g., \"%s\" not allowed)", 78 | "verified": false 79 | } 80 | ], 81 | "verified": false 82 | }, 83 | "name": "PasswordStrengthError", 84 | "statusCode": 400 85 | } -------------------------------------------------------------------------------- /src/main/java/com/auth0/client/mgmt/filter/UserFilter.java: -------------------------------------------------------------------------------- 1 | package com.auth0.client.mgmt.filter; 2 | 3 | /** 4 | * Class used to filter the results received when calling the Users endpoint. Related to the {@link com.auth0.client.mgmt.UsersEntity} entity. 5 | */ 6 | public class UserFilter extends QueryFilter { 7 | 8 | /** 9 | * Creates a new instance using the search engine 'v2'. 10 | *

11 | * This version of the search engine is now deprecated and will stop working on November 13th 2018. 12 | * Please, migrate as soon as possible and use the {@link #withSearchEngine(String)} method to specify version 'v3'. 13 | * See the migration guide at https://auth0.com/docs/users/search/v3#migrate-from-search-engine-v2-to-v3 14 | */ 15 | public UserFilter() { 16 | withSearchEngine("v2"); 17 | } 18 | 19 | @Override 20 | public UserFilter withTotals(boolean includeTotals) { 21 | super.withTotals(includeTotals); 22 | return this; 23 | } 24 | 25 | /** 26 | * Selects which Search Engine version to use. 27 | *

28 | * Version 2 is now deprecated and will stop working on November 13th 2018. Please, migrate as soon as possible to 'v3'. 29 | * See the migration guide at https://auth0.com/docs/users/search/v3#migrate-from-search-engine-v2-to-v3 30 | * 31 | * @param searchEngineVersion the search engine version to use on queries. 32 | * @return this filter instance 33 | */ 34 | public UserFilter withSearchEngine(String searchEngineVersion) { 35 | parameters.put("search_engine", searchEngineVersion); 36 | return this; 37 | } 38 | 39 | /** 40 | * Filter by a query 41 | * 42 | * @param query the query expression to use following the syntax defined at https://auth0.com/docs/users/search/v3/query-syntax 43 | * @return this filter instance 44 | */ 45 | @Override 46 | public UserFilter withQuery(String query) { 47 | super.withQuery(query); 48 | return this; 49 | } 50 | 51 | @Override 52 | public UserFilter withSort(String sort) { 53 | super.withSort(sort); 54 | return this; 55 | } 56 | 57 | @Override 58 | public UserFilter withPage(int pageNumber, int amountPerPage) { 59 | super.withPage(pageNumber, amountPerPage); 60 | return this; 61 | } 62 | 63 | @Override 64 | public UserFilter withFields(String fields, boolean includeFields) { 65 | super.withFields(fields, includeFields); 66 | return this; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/main/java/com/auth0/json/mgmt/ClientGrant.java: -------------------------------------------------------------------------------- 1 | package com.auth0.json.mgmt; 2 | 3 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 4 | import com.fasterxml.jackson.annotation.JsonInclude; 5 | import com.fasterxml.jackson.annotation.JsonProperty; 6 | 7 | import java.util.List; 8 | 9 | /** 10 | * Class that represents an Auth0 Client Grant object. Related to the {@link com.auth0.client.mgmt.ClientGrantsEntity} entity. 11 | */ 12 | @SuppressWarnings("unused") 13 | @JsonIgnoreProperties(ignoreUnknown = true) 14 | @JsonInclude(JsonInclude.Include.NON_NULL) 15 | public class ClientGrant { 16 | 17 | @JsonProperty("id") 18 | private String id; 19 | @JsonProperty("client_id") 20 | private String clientId; 21 | @JsonProperty("audience") 22 | private String audience; 23 | @JsonProperty("scope") 24 | private List scope; 25 | 26 | /** 27 | * Getter for the id of the client grant. 28 | * 29 | * @return the id. 30 | */ 31 | @JsonProperty("id") 32 | public String getId() { 33 | return id; 34 | } 35 | 36 | /** 37 | * Getter for the client id of the application. 38 | * 39 | * @return the application's client id. 40 | */ 41 | @JsonProperty("client_id") 42 | public String getClientId() { 43 | return clientId; 44 | } 45 | 46 | /** 47 | * Setter for the application's client id. 48 | * 49 | * @param clientId the application's client id to set. 50 | */ 51 | @JsonProperty("client_id") 52 | public void setClientId(String clientId) { 53 | this.clientId = clientId; 54 | } 55 | 56 | /** 57 | * Getter for the audience. 58 | * 59 | * @return the audience. 60 | */ 61 | @JsonProperty("audience") 62 | public String getAudience() { 63 | return audience; 64 | } 65 | 66 | /** 67 | * Setter for the audience. 68 | * 69 | * @param audience the audience to set. 70 | */ 71 | @JsonProperty("audience") 72 | public void setAudience(String audience) { 73 | this.audience = audience; 74 | } 75 | 76 | /** 77 | * Getter for the scope. 78 | * 79 | * @return the scope. 80 | */ 81 | @JsonProperty("scope") 82 | public List getScope() { 83 | return scope; 84 | } 85 | 86 | /** 87 | * Setter for the scope. 88 | * 89 | * @param scope the scope to set. 90 | */ 91 | @JsonProperty("scope") 92 | public void setScope(List scope) { 93 | this.scope = scope; 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /src/main/java/com/auth0/json/mgmt/guardian/GuardianTemplates.java: -------------------------------------------------------------------------------- 1 | package com.auth0.json.mgmt.guardian; 2 | 3 | import com.fasterxml.jackson.annotation.JsonCreator; 4 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 5 | import com.fasterxml.jackson.annotation.JsonInclude; 6 | import com.fasterxml.jackson.annotation.JsonProperty; 7 | 8 | /** 9 | * Class that represents an Auth0 Guardian SMS Templates object. Related to the {@link com.auth0.client.mgmt.GuardianEntity} entity. 10 | */ 11 | @SuppressWarnings({"unused", "WeakerAccess"}) 12 | @JsonIgnoreProperties(ignoreUnknown = true) 13 | @JsonInclude(JsonInclude.Include.NON_NULL) 14 | public class GuardianTemplates { 15 | 16 | @JsonProperty("enrollment_message") 17 | private String enrollmentMessage; 18 | @JsonProperty("verification_message") 19 | private String verificationMessage; 20 | 21 | @JsonCreator 22 | public GuardianTemplates(@JsonProperty("enrollment_message") String enrollmentMessage, @JsonProperty("verification_message") String verificationMessage) { 23 | this.enrollmentMessage = enrollmentMessage; 24 | this.verificationMessage = verificationMessage; 25 | } 26 | 27 | /** 28 | * Getter for the message to send when the user enrolls with SMS. 29 | * 30 | * @return the message to send upon enrollment. 31 | */ 32 | @JsonProperty("enrollment_message") 33 | public String getEnrollmentMessage() { 34 | return enrollmentMessage; 35 | } 36 | 37 | /** 38 | * Setter for the message to send when the user enrolls with SMS. 39 | * 40 | * @param enrollmentMessage the message to send upon enrollment. 41 | */ 42 | @JsonProperty("enrollment_message") 43 | public void setEnrollmentMessage(String enrollmentMessage) { 44 | this.enrollmentMessage = enrollmentMessage; 45 | } 46 | 47 | /** 48 | * Getter for the message to send when the user is prompted to verify their account via SMS. 49 | * 50 | * @return the message to send upon verification. 51 | */ 52 | @JsonProperty("verification_message") 53 | public String getVerificationMessage() { 54 | return verificationMessage; 55 | } 56 | 57 | /** 58 | * Setter for the message to send when the user is prompted to verify their account via SMS. 59 | * 60 | * @param verificationMessage the message to send upon verification. 61 | */ 62 | @JsonProperty("verification_message") 63 | public void setVerificationMessage(String verificationMessage) { 64 | this.verificationMessage = verificationMessage; 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/test/java/com/auth0/client/mgmt/filter/RulesFilterTest.java: -------------------------------------------------------------------------------- 1 | package com.auth0.client.mgmt.filter; 2 | 3 | import org.hamcrest.Matchers; 4 | import org.junit.Before; 5 | import org.junit.Test; 6 | 7 | import static org.hamcrest.CoreMatchers.is; 8 | import static org.hamcrest.CoreMatchers.notNullValue; 9 | import static org.junit.Assert.assertThat; 10 | 11 | public class RulesFilterTest { 12 | 13 | private RulesFilter filter; 14 | 15 | @Before 16 | public void setUp() throws Exception { 17 | filter = new RulesFilter(); 18 | } 19 | 20 | @Test 21 | public void shouldFilterWithEnabled() throws Exception { 22 | RulesFilter instance = filter.withEnabled(true); 23 | 24 | assertThat(filter, is(instance)); 25 | assertThat(filter.getAsMap(), is(notNullValue())); 26 | assertThat(filter.getAsMap(), Matchers.hasEntry("enabled", (Object) true)); 27 | } 28 | 29 | @Test 30 | public void shouldFilterWithFields() throws Exception { 31 | RulesFilter instance = filter.withFields("a,b,c", true); 32 | 33 | assertThat(filter, is(instance)); 34 | assertThat(filter.getAsMap(), is(notNullValue())); 35 | assertThat(filter.getAsMap(), Matchers.hasEntry("fields", (Object) "a,b,c")); 36 | assertThat(filter.getAsMap(), Matchers.hasEntry("include_fields", (Object) true)); 37 | } 38 | 39 | @Test 40 | public void shouldFilterWithoutFields() throws Exception { 41 | RulesFilter instance = filter.withFields("a,b,c", false); 42 | 43 | assertThat(filter, is(instance)); 44 | assertThat(filter.getAsMap(), is(notNullValue())); 45 | assertThat(filter.getAsMap(), Matchers.hasEntry("fields", (Object) "a,b,c")); 46 | assertThat(filter.getAsMap(), Matchers.hasEntry("include_fields", (Object) false)); 47 | } 48 | 49 | @Test 50 | public void shouldIncludeTotals() throws Exception { 51 | RulesFilter instance = filter.withTotals(true); 52 | 53 | assertThat(filter, is(instance)); 54 | assertThat(filter.getAsMap(), is(notNullValue())); 55 | assertThat(filter.getAsMap(), Matchers.hasEntry("include_totals", (Object) true)); 56 | } 57 | 58 | @Test 59 | public void shouldFilterByPage() throws Exception { 60 | RulesFilter instance = filter.withPage(15, 50); 61 | 62 | assertThat(filter, is(instance)); 63 | assertThat(filter.getAsMap(), is(notNullValue())); 64 | assertThat(filter.getAsMap(), Matchers.hasEntry("page", (Object) 15)); 65 | assertThat(filter.getAsMap(), Matchers.hasEntry("per_page", (Object) 50)); 66 | } 67 | } -------------------------------------------------------------------------------- /src/main/java/com/auth0/client/mgmt/BlacklistsEntity.java: -------------------------------------------------------------------------------- 1 | package com.auth0.client.mgmt; 2 | 3 | import com.auth0.json.mgmt.Token; 4 | import com.auth0.net.CustomRequest; 5 | import com.auth0.net.Request; 6 | import com.auth0.net.VoidRequest; 7 | import com.auth0.utils.Asserts; 8 | import com.fasterxml.jackson.core.type.TypeReference; 9 | import okhttp3.HttpUrl; 10 | import okhttp3.OkHttpClient; 11 | 12 | import java.util.List; 13 | 14 | /** 15 | * Class that provides an implementation of the Blacklists methods of the Management API as defined in https://auth0.com/docs/api/management/v2#!/Blacklists 16 | */ 17 | @SuppressWarnings("WeakerAccess") 18 | public class BlacklistsEntity extends BaseManagementEntity { 19 | 20 | BlacklistsEntity(OkHttpClient client, HttpUrl baseUrl, String apiToken) { 21 | super(client, baseUrl, apiToken); 22 | } 23 | 24 | /** 25 | * Request all the Blacklisted Tokens with a given audience. A token with scope blacklist:tokens is needed. 26 | * See https://auth0.com/docs/api/management/v2#!/Blacklists/get_tokens. 27 | * 28 | * @param audience the token audience (aud). 29 | * @return a Request to execute. 30 | */ 31 | public Request> getBlacklist(String audience) { 32 | Asserts.assertNotNull(audience, "audience"); 33 | 34 | String url = baseUrl 35 | .newBuilder() 36 | .addPathSegments("api/v2/blacklists/tokens") 37 | .addQueryParameter("aud", audience) 38 | .build() 39 | .toString(); 40 | CustomRequest> request = new CustomRequest<>(client, url, "GET", new TypeReference>() { 41 | }); 42 | request.addHeader("Authorization", "Bearer " + apiToken); 43 | return request; 44 | } 45 | 46 | /** 47 | * Add a Token to the Blacklist. A token with scope blacklist:tokens is needed. 48 | * See https://auth0.com/docs/api/management/v2#!/Blacklists/post_tokens. 49 | * 50 | * @param token the token to blacklist. 51 | * @return a Request to execute. 52 | */ 53 | public Request blacklistToken(Token token) { 54 | Asserts.assertNotNull(token, "token"); 55 | 56 | String url = baseUrl 57 | .newBuilder() 58 | .addPathSegments("api/v2/blacklists/tokens") 59 | .build() 60 | .toString(); 61 | VoidRequest request = new VoidRequest(client, url, "POST"); 62 | request.addHeader("Authorization", "Bearer " + apiToken); 63 | request.setBody(token); 64 | return request; 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/main/java/com/auth0/client/mgmt/filter/QueryFilter.java: -------------------------------------------------------------------------------- 1 | package com.auth0.client.mgmt.filter; 2 | 3 | import java.io.UnsupportedEncodingException; 4 | import java.net.URLEncoder; 5 | 6 | public class QueryFilter extends FieldsFilter { 7 | 8 | public static final String KEY_QUERY = "q"; 9 | 10 | /** 11 | * Filter by a query 12 | * 13 | * @param query the query expression to use 14 | * @return this filter instance 15 | */ 16 | public QueryFilter withQuery(String query) { 17 | try { 18 | String encodedQuery = urlEncode(query); 19 | parameters.put(KEY_QUERY, encodedQuery); 20 | return this; 21 | } catch (UnsupportedEncodingException ex) { 22 | //"Every implementation of the Java platform is required to support the following standard charsets [...]: UTF-8" 23 | //cf. https://docs.oracle.com/javase/7/docs/api/java/nio/charset/Charset.html 24 | throw new IllegalStateException("UTF-8 encoding not supported by current Java platform implementation.", ex); 25 | } 26 | } 27 | 28 | /** 29 | * Include the query summary 30 | * 31 | * @param includeTotals whether to include or not the query summary. 32 | * @return this filter instance 33 | */ 34 | public QueryFilter withTotals(boolean includeTotals) { 35 | parameters.put("include_totals", includeTotals); 36 | return this; 37 | } 38 | 39 | /** 40 | * Sort the query 41 | * 42 | * @param sort the field to use for sorting. Use 'field:order' where order is 1 for ascending and -1 for descending. 43 | * @return this filter instance 44 | */ 45 | public QueryFilter withSort(String sort) { 46 | parameters.put("sort", sort); 47 | return this; 48 | } 49 | 50 | /** 51 | * Filter by page 52 | * 53 | * @param pageNumber the page number to retrieve. 54 | * @param amountPerPage the amount of items per page to retrieve. 55 | * @return this filter instance 56 | */ 57 | public QueryFilter withPage(int pageNumber, int amountPerPage) { 58 | parameters.put("page", pageNumber); 59 | parameters.put("per_page", amountPerPage); 60 | return this; 61 | } 62 | 63 | @Override 64 | public QueryFilter withFields(String fields, boolean includeFields) { 65 | super.withFields(fields, includeFields); 66 | return this; 67 | } 68 | 69 | //Visible for testing 70 | String urlEncode(String query) throws UnsupportedEncodingException { 71 | return URLEncoder.encode(query, "UTF-8"); 72 | } 73 | 74 | } 75 | -------------------------------------------------------------------------------- /src/test/java/com/auth0/client/mgmt/filter/DeviceCredentialsFilterTest.java: -------------------------------------------------------------------------------- 1 | package com.auth0.client.mgmt.filter; 2 | 3 | import org.hamcrest.Matchers; 4 | import org.junit.Before; 5 | import org.junit.Test; 6 | 7 | import static org.hamcrest.CoreMatchers.is; 8 | import static org.hamcrest.CoreMatchers.notNullValue; 9 | import static org.junit.Assert.assertThat; 10 | 11 | public class DeviceCredentialsFilterTest { 12 | 13 | private DeviceCredentialsFilter filter; 14 | 15 | @Before 16 | public void setUp() throws Exception { 17 | filter = new DeviceCredentialsFilter(); 18 | } 19 | 20 | @Test 21 | public void shouldFilterByClientId() throws Exception { 22 | DeviceCredentialsFilter instance = filter.withClientId("1234567890"); 23 | 24 | assertThat(filter, is(instance)); 25 | assertThat(filter.getAsMap(), is(notNullValue())); 26 | assertThat(filter.getAsMap(), Matchers.hasEntry("client_id", (Object) "1234567890")); 27 | } 28 | 29 | @Test 30 | public void shouldFilterByType() throws Exception { 31 | DeviceCredentialsFilter instance = filter.withType("public_key"); 32 | 33 | assertThat(filter, is(instance)); 34 | assertThat(filter.getAsMap(), is(notNullValue())); 35 | assertThat(filter.getAsMap(), Matchers.hasEntry("type", (Object) "public_key")); 36 | } 37 | 38 | @Test 39 | public void shouldFilterByUserId() throws Exception { 40 | DeviceCredentialsFilter instance = filter.withUserId("1234567890"); 41 | 42 | assertThat(filter, is(instance)); 43 | assertThat(filter.getAsMap(), is(notNullValue())); 44 | assertThat(filter.getAsMap(), Matchers.hasEntry("user_id", (Object) "1234567890")); 45 | } 46 | 47 | @Test 48 | public void shouldFilterWithFields() throws Exception { 49 | DeviceCredentialsFilter instance = filter.withFields("a,b,c", true); 50 | 51 | assertThat(filter, is(instance)); 52 | assertThat(filter.getAsMap(), is(notNullValue())); 53 | assertThat(filter.getAsMap(), Matchers.hasEntry("fields", (Object) "a,b,c")); 54 | assertThat(filter.getAsMap(), Matchers.hasEntry("include_fields", (Object) true)); 55 | } 56 | 57 | @Test 58 | public void shouldFilterWithoutFields() throws Exception { 59 | DeviceCredentialsFilter instance = filter.withFields("a,b,c", false); 60 | 61 | assertThat(filter, is(instance)); 62 | assertThat(filter.getAsMap(), is(notNullValue())); 63 | assertThat(filter.getAsMap(), Matchers.hasEntry("fields", (Object) "a,b,c")); 64 | assertThat(filter.getAsMap(), Matchers.hasEntry("include_fields", (Object) false)); 65 | } 66 | } -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /src/test/java/com/auth0/json/mgmt/EmailTemplateTest.java: -------------------------------------------------------------------------------- 1 | package com.auth0.json.mgmt; 2 | 3 | import com.auth0.json.JsonMatcher; 4 | import com.auth0.json.JsonTest; 5 | import org.junit.Test; 6 | 7 | import static org.hamcrest.MatcherAssert.assertThat; 8 | import static org.hamcrest.Matchers.is; 9 | import static org.hamcrest.Matchers.notNullValue; 10 | 11 | public class EmailTemplateTest extends JsonTest { 12 | 13 | private static final String json = "{\"template\": \"welcome_email\", \"from\": \"you@auth0.com\", \"subject\": \"Some subject\", \"syntax\": \"liquid\", \"body\": \" \", \"enabled\": true}"; 14 | 15 | @Test 16 | public void shouldSerialize() throws Exception { 17 | EmailTemplate template = new EmailTemplate(); 18 | template.setResultUrl("https://auth0.com"); 19 | template.setUrlLifetimeInSeconds(993311); 20 | template.setBody("SOME HTML"); 21 | template.setEnabled(false); 22 | template.setSyntax("html"); 23 | template.setSubject("Hello world"); 24 | template.setFrom("me@auth0.com"); 25 | template.setName("farewell"); 26 | 27 | String serialized = toJSON(template); 28 | assertThat(serialized, is(notNullValue())); 29 | assertThat(serialized, JsonMatcher.hasEntry("resultUrl", "https://auth0.com")); 30 | assertThat(serialized, JsonMatcher.hasEntry("urlLifetimeInSeconds", 993311)); 31 | assertThat(serialized, JsonMatcher.hasEntry("body", "SOME HTML")); 32 | assertThat(serialized, JsonMatcher.hasEntry("enabled", false)); 33 | assertThat(serialized, JsonMatcher.hasEntry("syntax", "html")); 34 | assertThat(serialized, JsonMatcher.hasEntry("subject", "Hello world")); 35 | assertThat(serialized, JsonMatcher.hasEntry("from", "me@auth0.com")); 36 | assertThat(serialized, JsonMatcher.hasEntry("template", "farewell")); 37 | } 38 | 39 | @Test 40 | public void shouldDeserialize() throws Exception { 41 | EmailTemplate template = fromJSON(json, EmailTemplate.class); 42 | 43 | assertThat(template, is(notNullValue())); 44 | assertThat(template.getName(), is("welcome_email")); 45 | assertThat(template.getFrom(), is("you@auth0.com")); 46 | assertThat(template.getSubject(), is("Some subject")); 47 | assertThat(template.getSyntax(), is("liquid")); 48 | assertThat(template.getBody(), is(" ")); 49 | assertThat(template.isEnabled(), is(true)); 50 | } 51 | 52 | @Test 53 | public void shouldHaveDefaults() { 54 | EmailTemplate template = new EmailTemplate(); 55 | assertThat(template.getSyntax(), is("liquid")); 56 | } 57 | } --------------------------------------------------------------------------------