Search in sources :

Example 1 with APIException

use of com.auth0.exception.APIException in project CollectiveOneWebapp by CollectiveOne.

the class AppUserService method updateUserDataInLocalDB.

@Transactional
public Boolean updateUserDataInLocalDB(UUID c1Id) {
    AppUser appUser = appUserRepository.findByC1Id(c1Id);
    try {
        User auth0User = mgmt.users().get(appUser.getAuth0Ids().get(0), null).execute();
        appUser.getProfile().setPictureUrl(auth0User.getPicture());
        appUserRepository.save(appUser);
        return true;
    } catch (APIException exception) {
        System.out.println(exception.getMessage());
    } catch (Auth0Exception exception) {
        System.out.println(exception.getMessage());
    }
    return false;
}
Also used : User(com.auth0.json.mgmt.users.User) APIException(com.auth0.exception.APIException) Auth0Exception(com.auth0.exception.Auth0Exception) Transactional(javax.transaction.Transactional)

Example 2 with APIException

use of com.auth0.exception.APIException in project CollectiveOneWebapp by CollectiveOne.

the class AppUserService method addUserToLocalDB.

@Transactional
private AppUser addUserToLocalDB(String auth0Id) {
    /* retrieve from Auth0 */
    AppUser appUser = null;
    User auth0User = null;
    if (auth0Id.equals("anonymousUser")) {
        return null;
    }
    try {
        auth0User = mgmt.users().get(auth0Id, null).execute();
        /* check if this email is already registered. */
        appUser = appUserRepository.findByEmail(auth0User.getEmail());
        if (appUser == null) {
            // if (auth0User.isEmailVerified()) {
            if (true) {
                /* create a new user if not */
                appUser = new AppUser();
                appUser.getAuth0Ids().add((auth0User.getId()));
                appUser.setEmail(auth0User.getEmail());
                appUser.setEmailNotificationsEnabled(true);
                AppUserProfile profile = new AppUserProfile();
                if (auth0User.getIdentities().get(0).getProvider().equals("auth0")) {
                    profile.setNickname(auth0User.getNickname());
                } else {
                    profile.setNickname(auth0User.getName());
                }
                profile.setUser(appUser);
                profile.setPictureUrl(auth0User.getPicture());
                profile = appUserProfileRepository.save(profile);
                appUser.setProfile(profile);
            }
        } else {
            /* just add the auth0id to the existing user */
            appUser.getAuth0Ids().add(auth0Id);
        }
        appUser = appUserRepository.save(appUser);
    } catch (APIException exception) {
        System.out.println(exception.getMessage());
    } catch (Auth0Exception exception) {
        System.out.println(exception.getMessage());
    }
    return appUser;
}
Also used : User(com.auth0.json.mgmt.users.User) APIException(com.auth0.exception.APIException) Auth0Exception(com.auth0.exception.Auth0Exception) Transactional(javax.transaction.Transactional)

Example 3 with APIException

use of com.auth0.exception.APIException in project CollectiveOneWebapp by CollectiveOne.

the class Auth0Management method managementAPI.

@Bean
public ManagementAPI managementAPI() {
    String token = "";
    AuthRequest authRequest = authAPI.requestToken("https://collectiveone.auth0.com/api/v2/");
    try {
        TokenHolder holder = authRequest.execute();
        token = holder.getAccessToken();
    } catch (APIException exception) {
        System.out.println(exception.getMessage());
    } catch (Auth0Exception exception) {
        System.out.println(exception.getMessage());
    }
    return new ManagementAPI(issuer, token);
}
Also used : AuthRequest(com.auth0.net.AuthRequest) ManagementAPI(com.auth0.client.mgmt.ManagementAPI) APIException(com.auth0.exception.APIException) Auth0Exception(com.auth0.exception.Auth0Exception) TokenHolder(com.auth0.json.auth.TokenHolder) Bean(org.springframework.context.annotation.Bean)

Aggregations

APIException (com.auth0.exception.APIException)3 Auth0Exception (com.auth0.exception.Auth0Exception)3 User (com.auth0.json.mgmt.users.User)2 Transactional (javax.transaction.Transactional)2 ManagementAPI (com.auth0.client.mgmt.ManagementAPI)1 TokenHolder (com.auth0.json.auth.TokenHolder)1 AuthRequest (com.auth0.net.AuthRequest)1 Bean (org.springframework.context.annotation.Bean)1