use of uk.ac.cam.cl.dtg.isaac.dos.users.FacebookUser in project isaac-api by isaacphysics.
the class FacebookAuthenticator method getUserInfo.
@Override
public synchronized UserFromAuthProvider getUserInfo(final String internalProviderReference) throws NoUserException, AuthenticatorSecurityException {
Credential credentials = credentialStore.get(internalProviderReference);
if (verifyAccessTokenIsValid(credentials)) {
log.debug("Successful Verification of access token with provider.");
} else {
log.error("Unable to verify access token - it could be an indication of fraud.");
throw new AuthenticatorSecurityException("Access token is invalid - the client id returned by the identity provider does not match ours.");
}
FacebookUser userInfo = null;
try {
GenericUrl url = new GenericUrl(USER_INFO_URL + "?fields=" + requestedFields);
url.set("access_token", credentials.getAccessToken());
userInfo = JsonLoader.load(inputStreamToString(url.toURL().openStream()), FacebookUser.class, true);
log.debug("Retrieved User info from Facebook");
} catch (IOException e) {
log.error("An IO error occurred while trying to retrieve user information: " + e);
}
if (userInfo != null && userInfo.getId() != null) {
EmailVerificationStatus emailStatus = userInfo.isVerified() ? EmailVerificationStatus.VERIFIED : EmailVerificationStatus.NOT_VERIFIED;
String email = userInfo.getEmail();
if (null == email) {
email = userInfo.getId() + "-facebook";
emailStatus = EmailVerificationStatus.DELIVERY_FAILED;
log.warn("No email address provided by Facebook! Using (" + email + ") instead");
}
return new UserFromAuthProvider(userInfo.getId(), userInfo.getFirstName(), userInfo.getLastName(), email, emailStatus, null, null, null);
} else {
throw new NoUserException("No user could be created from provider details!");
}
}
Aggregations