Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
robingenz committed Jan 24, 2025
1 parent a949062 commit 80fb9b0
Showing 1 changed file with 33 additions and 38 deletions.
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
package io.capawesome.capacitorjs.plugins.firebase.authentication.handlers;

import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.credentials.ClearCredentialStateRequest;
import androidx.credentials.Credential;
import androidx.credentials.CredentialManager;

import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.credentials.CredentialManagerCallback;
import androidx.credentials.GetCredentialRequest;
import androidx.credentials.GetCredentialResponse;
import androidx.credentials.exceptions.ClearCredentialException;
import androidx.credentials.exceptions.GetCredentialException;

import com.getcapacitor.Logger;
import com.getcapacitor.PluginCall;
import com.google.android.libraries.identity.googleid.GetGoogleIdOption;
Expand All @@ -21,7 +19,6 @@
import io.capawesome.capacitorjs.plugins.firebase.authentication.FirebaseAuthentication;
import io.capawesome.capacitorjs.plugins.firebase.authentication.R;
import io.capawesome.capacitorjs.plugins.firebase.authentication.interfaces.EmptyResultCallback;

import java.util.concurrent.Executor;
import java.util.concurrent.Executors;

Expand All @@ -46,20 +43,20 @@ public void signOut() {
Executor executor = Executors.newSingleThreadExecutor();
CredentialManager credentialManager = CredentialManager.create(pluginImplementation.getPlugin().getActivity());
credentialManager.clearCredentialStateAsync(
request,
null,
executor,
new CredentialManagerCallback<Void, ClearCredentialException>() {
@Override
public void onResult(Void result) {
// No-op
}
request,
null,
executor,
new CredentialManagerCallback<Void, ClearCredentialException>() {
@Override
public void onResult(Void result) {
// No-op
}

@Override
public void onError(@NonNull ClearCredentialException exception) {
// No-op
}
@Override
public void onError(@NonNull ClearCredentialException exception) {
// No-op
}
}
);
}

Expand Down Expand Up @@ -89,31 +86,29 @@ private void handleGetCredentialResult(final PluginCall call, final boolean isLi
public void signInOrLink(final PluginCall call, final boolean isLink) {
Executor executor = Executors.newSingleThreadExecutor();
GetGoogleIdOption googleIdOption = new GetGoogleIdOption.Builder()
// Your server's client ID, not your Android client ID
.setServerClientId(pluginImplementation.getPlugin().getContext().getString(R.string.default_web_client_id))
// Show all accounts on the device (not just the accounts that have been used previously)
.setFilterByAuthorizedAccounts(false)
.build();
GetCredentialRequest request = new GetCredentialRequest.Builder()
.addCredentialOption(googleIdOption)
.build();
// Your server's client ID, not your Android client ID
.setServerClientId(pluginImplementation.getPlugin().getContext().getString(R.string.default_web_client_id))
// Show all accounts on the device (not just the accounts that have been used previously)
.setFilterByAuthorizedAccounts(false)
.build();
GetCredentialRequest request = new GetCredentialRequest.Builder().addCredentialOption(googleIdOption).build();
CredentialManager credentialManager = CredentialManager.create(pluginImplementation.getPlugin().getActivity());
credentialManager.getCredentialAsync(
pluginImplementation.getPlugin().getContext(),
request,
null,
executor,
new CredentialManagerCallback<GetCredentialResponse, GetCredentialException>() {
@Override
public void onResult(GetCredentialResponse response) {
handleGetCredentialResult(call, isLink, response);
}
pluginImplementation.getPlugin().getContext(),
request,
null,
executor,
new CredentialManagerCallback<GetCredentialResponse, GetCredentialException>() {
@Override
public void onResult(GetCredentialResponse response) {
handleGetCredentialResult(call, isLink, response);
}

@Override
public void onError(@NonNull GetCredentialException exception) {
handleGetCredentialError(call, isLink, exception);
}
@Override
public void onError(@NonNull GetCredentialException exception) {
handleGetCredentialError(call, isLink, exception);
}
}
);
}
}

0 comments on commit 80fb9b0

Please sign in to comment.