use of com.auth0.exception.Auth0Exception 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;
}
use of com.auth0.exception.Auth0Exception 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;
}
use of com.auth0.exception.Auth0Exception 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);
}
Aggregations