Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix Android
  • Loading branch information
stuartmorgan-g committed Aug 18, 2025
commit 3101fb3d3e732d42a21123c76f3be7c082ab3d1f
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ dependencies {
implementation 'androidx.credentials:credentials:1.5.0'
implementation 'androidx.credentials:credentials-play-services-auth:1.5.0'
implementation 'com.google.android.libraries.identity.googleid:googleid:1.1.1'
implementation 'com.google.android.gms:play-services-auth:21.3.0'
implementation 'com.google.android.gms:play-services-auth:21.4.0'
testImplementation 'junit:junit:4.13.2'
testImplementation 'org.mockito:mockito-inline:5.2.0'
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import com.google.android.gms.auth.api.identity.AuthorizationClient;
import com.google.android.gms.auth.api.identity.AuthorizationRequest;
import com.google.android.gms.auth.api.identity.AuthorizationResult;
import com.google.android.gms.auth.api.identity.ClearTokenRequest;
import com.google.android.gms.auth.api.identity.Identity;
import com.google.android.gms.common.api.ApiException;
import com.google.android.gms.common.api.Scope;
Expand Down Expand Up @@ -331,12 +332,12 @@ public void clearCredentialState(@NonNull Function1<? super Result<Unit>, Unit>
new CredentialManagerCallback<>() {
@Override
public void onResult(Void result) {
ResultUtilsKt.completeWithClearCredentialStateSuccess(callback);
ResultUtilsKt.completeWithUnitSuccess(callback);
}

@Override
public void onError(@NonNull ClearCredentialException e) {
ResultUtilsKt.completeWithClearCredentialStateError(
ResultUtilsKt.completeWithUnitError(
callback, new FlutterError("Clear Failed", e.getMessage(), null));
}
});
Expand All @@ -347,14 +348,14 @@ public void clearAuthorizationToken(
@NonNull String token, @NonNull Function1<? super Result<Unit>, Unit> callback) {
authorizationClientFactory
.create(context)
.clearToken(token)
.clearToken(ClearTokenRequest.builder().setToken(token).build())
.addOnSuccessListener(
(Void) -> {
ResultUtilsKt.completeWithUnitSuccess(callback);
})
.addOnFailureListener(
(Exception e) -> {
ResultUtilsKt.completeWithFlutterError(
ResultUtilsKt.completeWithUnitError(
callback,
new FlutterError("clearAuthorizationToken failed", e.getMessage(), null));
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ fun completeWithGetCredentialFailure(
callback(Result.success(failure))
}

fun completeWithClearCredentialStateSuccess(callback: (Result<Unit>) -> Unit) {
fun completeWithUnitSuccess(callback: (Result<Unit>) -> Unit) {
callback(Result.success(Unit))
}

fun completeWithClearCredentialStateError(callback: (Result<Unit>) -> Unit, failure: FlutterError) {
fun completeWithUnitError(callback: (Result<Unit>) -> Unit, failure: FlutterError) {
callback(Result.failure(failure))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import com.google.android.gms.auth.api.identity.AuthorizationClient;
import com.google.android.gms.auth.api.identity.AuthorizationRequest;
import com.google.android.gms.auth.api.identity.AuthorizationResult;
import com.google.android.gms.auth.api.identity.ClearTokenRequest;
import com.google.android.gms.common.api.ApiException;
import com.google.android.gms.common.api.Status;
import com.google.android.gms.tasks.OnSuccessListener;
Expand Down Expand Up @@ -71,6 +72,7 @@ public class GoogleSignInTest {
@Mock CustomCredential mockGenericCredential;
@Mock GoogleIdTokenCredential mockGoogleCredential;
@Mock Task<AuthorizationResult> mockAuthorizationTask;
@Mock Task<Void> mockClearTokenTask;

private GoogleSignInPlugin flutterPlugin;
// Technically this is not the plugin, but in practice almost all of the functionality is in this
Expand All @@ -88,6 +90,8 @@ public void setUp() {
.thenReturn(GoogleIdTokenCredential.TYPE_GOOGLE_ID_TOKEN_CREDENTIAL);
when(mockAuthorizationTask.addOnSuccessListener(any())).thenReturn(mockAuthorizationTask);
when(mockAuthorizationTask.addOnFailureListener(any())).thenReturn(mockAuthorizationTask);
when(mockClearTokenTask.addOnSuccessListener(any())).thenReturn(mockClearTokenTask);
when(mockClearTokenTask.addOnFailureListener(any())).thenReturn(mockClearTokenTask);
when(mockAuthorizationIntent.getIntentSender()).thenReturn(mockAuthorizationIntentSender);
when(mockActivityPluginBinding.getActivity()).thenReturn(mockActivity);

Expand Down Expand Up @@ -1100,10 +1104,10 @@ public void clearCredentialState_reportsFailure() {

@Test
public void clearAuthorizationToken_callsClient() {
final Task<Void> mockTask = mock(Task.class);
when(mockAuthorizationClient.clearToken(any())).thenReturn(mockTask);
final String testToken = "testToken";
when(mockAuthorizationClient.clearToken(any())).thenReturn(mockClearTokenTask);
plugin.clearAuthorizationToken(
"test_token",
testToken,
ResultCompat.asCompatCallback(
reply -> {
// This test doesn't trigger the getCredentialsAsync callback that would call this,
Expand All @@ -1112,6 +1116,11 @@ public void clearAuthorizationToken_callsClient() {
return null;
}));

verify(mockAuthorizationClient).clearToken("test_token");
ArgumentCaptor<ClearTokenRequest> authRequestCaptor =
ArgumentCaptor.forClass(ClearTokenRequest.class);
verify(mockAuthorizationClient).clearToken(authRequestCaptor.capture());

ClearTokenRequest request = authRequestCaptor.getValue();
assertEquals(testToken, request.getToken());
}
}