Search in sources :

Example 1 with FirebaseToken

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;
}
Also used : UsernameNotFoundException(org.springframework.security.core.userdetails.UsernameNotFoundException) FirebaseToken(com.google.firebase.auth.FirebaseToken) UserDetails(org.springframework.security.core.userdetails.UserDetails) UserAuth(amu.zhcet.auth.UserAuth) ExecutionException(java.util.concurrent.ExecutionException)

Example 2 with FirebaseToken

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);
    }
}
Also used : FirebaseToken(com.google.firebase.auth.FirebaseToken) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

FirebaseToken (com.google.firebase.auth.FirebaseToken)2 ExecutionException (java.util.concurrent.ExecutionException)2 UserAuth (amu.zhcet.auth.UserAuth)1 UserDetails (org.springframework.security.core.userdetails.UserDetails)1 UsernameNotFoundException (org.springframework.security.core.userdetails.UsernameNotFoundException)1