Skip to content

Commit

Permalink
feat(authentication): migrate to Credential Manager on Android (#803)
Browse files Browse the repository at this point in the history
* wip

* wip

* wip

* wip

* wip

* revert

* wip

* revert

* wip

* style: format
  • Loading branch information
robingenz authored Jan 25, 2025
1 parent b811519 commit cd91e6c
Show file tree
Hide file tree
Showing 11 changed files with 267 additions and 126 deletions.
7 changes: 7 additions & 0 deletions packages/authentication/BREAKING.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,18 @@ This is a comprehensive list of the breaking changes introduced in the major ver

## Versions

- [Version 7.x.x](#version-6xx)
- [Version 6.x.x](#version-6xx)
- [Version 5.x.x](#version-5xx)
- [Version 1.x.x](#version-1xx)
- [Version 0.4.x](#version-04x)

## Version 7.x.x

### Google Sign-In

On **Android**, the `accessToken` and `serverAuthCode` are now only requested when the `scopes` option is set.

## Version 6.x.x

### Dependencies
Expand Down
9 changes: 9 additions & 0 deletions packages/authentication/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ ext {
firebaseAuthVersion = project.hasProperty('firebaseAuthVersion') ? rootProject.ext.firebaseAuthVersion : '22.3.1'
playServicesAuthVersion = project.hasProperty('playServicesAuthVersion') ? rootProject.ext.playServicesAuthVersion : '21.0.0'
facebookLoginVersion = project.hasProperty('facebookLoginVersion') ? rootProject.ext.facebookLoginVersion : '16.3.0'
androidxCredentialsVersion = project.hasProperty('androidxCredentialsVersion') ? rootProject.ext.androidxCredentialsVersion : '1.5.0-rc01'
androidxCredentialsPlayServicesAuthVersion = project.hasProperty('androidxCredentialsPlayServicesAuthVersion') ? rootProject.ext.androidxCredentialsPlayServicesAuthVersion : '1.5.0-rc01'
librariesIdentityGoogleidVersion = project.hasProperty('librariesIdentityGoogleidVersion') ? rootProject.ext.librariesIdentityGoogleidVersion : '1.1.1'
}

buildscript {
Expand Down Expand Up @@ -60,8 +63,14 @@ dependencies {
implementation "com.google.firebase:firebase-auth:$firebaseAuthVersion"
if (rgcfaIncludeGoogle) {
implementation "com.google.android.gms:play-services-auth:$playServicesAuthVersion"
implementation "androidx.credentials:credentials:$androidxCredentialsVersion"
implementation "androidx.credentials:credentials-play-services-auth:$androidxCredentialsPlayServicesAuthVersion"
implementation "com.google.android.libraries.identity.googleid:googleid:$librariesIdentityGoogleidVersion"
} else {
compileOnly "com.google.android.gms:play-services-auth:$playServicesAuthVersion"
compileOnly "androidx.credentials:credentials:$androidxCredentialsVersion"
compileOnly "androidx.credentials:credentials-play-services-auth:$androidxCredentialsPlayServicesAuthVersion"
compileOnly "com.google.android.libraries.identity.googleid:googleid:$librariesIdentityGoogleidVersion"
}
if (rgcfaIncludeFacebook) {
implementation "com.facebook.android:facebook-login:$facebookLoginVersion"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,21 @@
import static io.capawesome.capacitorjs.plugins.firebase.authentication.FirebaseAuthenticationPlugin.ERROR_NO_USER_SIGNED_IN;
import static io.capawesome.capacitorjs.plugins.firebase.authentication.FirebaseAuthenticationPlugin.TAG;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import androidx.activity.result.ActivityResult;
import androidx.activity.result.ActivityResultLauncher;
import androidx.activity.result.IntentSenderRequest;
import androidx.activity.result.contract.ActivityResultContracts;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.getcapacitor.JSObject;
import com.getcapacitor.Logger;
import com.getcapacitor.PluginCall;
import com.google.android.gms.auth.api.identity.AuthorizationResult;
import com.google.android.gms.auth.api.identity.Identity;
import com.google.android.gms.common.api.ApiException;
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.ActionCodeSettings;
import com.google.firebase.auth.AdditionalUserInfo;
Expand All @@ -20,7 +27,6 @@
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.auth.GetTokenResult;
import com.google.firebase.auth.PhoneAuthCredential;
import com.google.firebase.auth.UserProfileChangeRequest;
import io.capawesome.capacitorjs.plugins.firebase.authentication.FirebaseAuthenticationHelper.ProviderId;
import io.capawesome.capacitorjs.plugins.firebase.authentication.classes.ConfirmVerificationCodeOptions;
Expand All @@ -43,8 +49,6 @@
import io.capawesome.capacitorjs.plugins.firebase.authentication.handlers.PlayGamesAuthProviderHandler;
import io.capawesome.capacitorjs.plugins.firebase.authentication.interfaces.EmptyResultCallback;
import io.capawesome.capacitorjs.plugins.firebase.authentication.interfaces.NonEmptyResultCallback;
import io.capawesome.capacitorjs.plugins.firebase.authentication.interfaces.Result;
import io.capawesome.capacitorjs.plugins.firebase.authentication.interfaces.ResultCallback;
import java.util.Arrays;
import java.util.List;
import org.json.JSONObject;
Expand All @@ -58,6 +62,7 @@ public class FirebaseAuthentication {
private AppleAuthProviderHandler appleAuthProviderHandler;
private FacebookAuthProviderHandler facebookAuthProviderHandler;
private GoogleAuthProviderHandler googleAuthProviderHandler;
public ActivityResultLauncher<IntentSenderRequest> googleAuthorizationResultLauncher;
private OAuthProviderHandler oAuthProviderHandler;
private PhoneAuthProviderHandler phoneAuthProviderHandler;
private PlayGamesAuthProviderHandler playGamesAuthProviderHandler;
Expand Down Expand Up @@ -646,14 +651,6 @@ public void startActivityForResult(final PluginCall call, Intent intent, String
plugin.startActivityForResult(call, intent, callbackName);
}

public void handleGoogleAuthProviderSignInActivityResult(@NonNull final PluginCall call, @NonNull ActivityResult result) {
googleAuthProviderHandler.handleOnActivityResult(call, result, false);
}

public void handleGoogleAuthProviderLinkActivityResult(@NonNull final PluginCall call, @NonNull ActivityResult result) {
googleAuthProviderHandler.handleOnActivityResult(call, result, true);
}

public void handlePlayGamesAuthProviderSignInActivityResult(@NonNull final PluginCall call, @NonNull ActivityResult result) {
playGamesAuthProviderHandler.handleOnActivityResult(call, result, false);
}
Expand Down Expand Up @@ -890,7 +887,7 @@ public void handleSuccessfulLink(final PluginCall call) {
call.resolve(linkResult);
}

public void handleFailedLink(final PluginCall call, String message, Exception exception) {
public void handleFailedLink(final PluginCall call, @Nullable String message, Exception exception) {
if (message == null && exception != null) {
message = exception.getMessage();
}
Expand Down Expand Up @@ -924,7 +921,7 @@ public FirebaseAuthenticationConfig getConfig() {
}

private void initAuthProviderHandlers(FirebaseAuthenticationConfig config) {
List providerList = Arrays.asList(config.getProviders());
List<String> providerList = Arrays.asList(config.getProviders());
if (providerList.contains(ProviderId.APPLE)) {
appleAuthProviderHandler = new AppleAuthProviderHandler(this);
}
Expand All @@ -933,6 +930,13 @@ private void initAuthProviderHandlers(FirebaseAuthenticationConfig config) {
}
if (providerList.contains(ProviderId.GOOGLE)) {
googleAuthProviderHandler = new GoogleAuthProviderHandler(this);
googleAuthorizationResultLauncher =
getPlugin()
.getActivity()
.registerForActivityResult(
new ActivityResultContracts.StartIntentSenderForResult(),
result -> googleAuthProviderHandler.handleActivityResult(result)
);
}
if (providerList.contains(ProviderId.PHONE)) {
phoneAuthProviderHandler = new PhoneAuthProviderHandler(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public class FirebaseAuthenticationPlugin extends Plugin {
"signInAnonymously cannot be used in combination with skipNativeAuth.";
public static final String AUTH_STATE_CHANGE_EVENT = "authStateChange";
public static final String ID_TOKEN_CHANGE_EVENT = "idTokenChange";

private FirebaseAuthenticationConfig config;
private FirebaseAuthentication implementation;

Expand Down Expand Up @@ -1009,22 +1010,6 @@ protected void handleOnActivityResult(int requestCode, int resultCode, @Nullable
implementation.handleOnActivityResult(requestCode, resultCode, data);
}

@ActivityCallback
private void handleGoogleAuthProviderSignInActivityResult(@Nullable PluginCall call, @Nullable ActivityResult result) {
if (call == null || result == null) {
return;
}
implementation.handleGoogleAuthProviderSignInActivityResult(call, result);
}

@ActivityCallback
private void handleGoogleAuthProviderLinkActivityResult(@Nullable PluginCall call, @Nullable ActivityResult result) {
if (call == null || result == null) {
return;
}
implementation.handleGoogleAuthProviderLinkActivityResult(call, result);
}

@ActivityCallback
private void handlePlayGamesAuthProviderSignInActivityResult(@Nullable PluginCall call, @Nullable ActivityResult result) {
if (call == null || result == null) {
Expand Down
Loading

0 comments on commit cd91e6c

Please sign in to comment.