use of com.google.firebase.auth.FirebaseToken in project zhcet-web by zhcet-amu.
the class FirebaseAuthenticationProvider method authenticate.
@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
if (!firebaseService.canProceed())
// Firebase is disabled, so we cannot proceed
return null;
String token = authentication.getCredentials().toString();
if (Strings.isNullOrEmpty(token))
// Cannot parse empty token
return null;
try {
FirebaseToken decodedToken = FirebaseService.getToken(token);
log.debug("User Claims: {}", decodedToken.getClaims());
UserDetails user = retrieveUser(decodedToken);
if (user == null)
throwBadCredentialsException();
userDetailsChecker.check(user);
if (user instanceof UserAuth) {
firebaseAccountMergeService.mergeFirebaseDetails((UserAuth) user, decodedToken);
} else {
log.warn("User {} is not of UserAuth Type", user);
}
return createSuccessAuthentication(user, authentication);
} catch (InterruptedException | ExecutionException e) {
log.warn("Unable to decode Firebase token");
throwBadCredentialsException();
} catch (UsernameNotFoundException une) {
throwBadCredentialsException();
}
return null;
}
use of com.google.firebase.auth.FirebaseToken in project zhcet-web by zhcet-amu.
the class AuthLinkService method linkAccount.
/**
* Links authenticated user to one of the Identity providers, like Google
* Also merges the provider data like email, verification status, and photo into user account
* NOTE: Only to be called from an authenticated endpoint
* @param token String: Firebase Authentication Token
*/
public void linkAccount(UserAuth userAuth, String token) {
if (!firebaseService.canProceed())
return;
try {
FirebaseToken decodedToken = FirebaseService.getToken(token);
log.info(decodedToken.getClaims().toString());
firebaseAccountMergeService.mergeFirebaseDetails(userAuth, decodedToken);
} catch (ExecutionException | InterruptedException e) {
log.error("Error linking data", e);
}
}
Aggregations