capacitor-native-google-one-tap-signin 0.0.21 → 0.0.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -8,6 +8,8 @@ Currently the idToken, id (e-mail), displayName, givenName, familyName, profileP
8
8
 
9
9
  The user is automatically signed-in, without a prompt after the first sign-in.
10
10
 
11
+ API version 29 or higher seems to be required for one-tap sign-in to work.
12
+
11
13
 
12
14
  # Demos
13
15
  See the `demo` folder.
Binary file
@@ -14,7 +14,7 @@ apply plugin: 'com.android.library'
14
14
  android {
15
15
  compileSdkVersion 31
16
16
  defaultConfig {
17
- minSdkVersion 22
17
+ minSdkVersion 29
18
18
  targetSdkVersion 31
19
19
  versionCode 1
20
20
  versionName "1.0"
@@ -44,10 +44,12 @@ repositories {
44
44
  dependencies {
45
45
  implementation fileTree(dir: 'libs', include: ['*.jar'])
46
46
  implementation project(':capacitor-android')
47
- implementation 'androidx.appcompat:appcompat:1.2.0'
47
+ implementation 'androidx.appcompat:appcompat:1.4.2'
48
48
  testImplementation 'junit:junit:4.13'
49
49
  androidTestImplementation 'com.android.support.test:runner:1.0.2'
50
50
  androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
51
51
  implementation 'com.google.android.gms:play-services-auth:20.4.1'
52
+ implementation 'com.google.android.gms:play-services-tasks:18.0.2'
53
+ implementation 'com.google.android.gms:play-services-base:18.0.1'
52
54
  }
53
55
 
@@ -1,6 +1,7 @@
1
1
  package com.proventask.capacitor.GoogleOneTapAuth;
2
2
 
3
3
  import android.app.Activity;
4
+ import android.content.Context;
4
5
  import android.content.Intent;
5
6
  import android.util.Log;
6
7
 
@@ -15,15 +16,12 @@ import com.getcapacitor.Plugin;
15
16
  import com.getcapacitor.PluginCall;
16
17
  import com.getcapacitor.PluginMethod;
17
18
  import com.getcapacitor.annotation.CapacitorPlugin;
18
- import com.google.android.gms.auth.api.credentials.Credentials;
19
- import com.google.android.gms.auth.api.credentials.CredentialsClient;
20
19
  import com.google.android.gms.auth.api.identity.BeginSignInRequest;
21
20
  import com.google.android.gms.auth.api.identity.BeginSignInResult;
22
21
  import com.google.android.gms.auth.api.identity.Identity;
23
22
  import com.google.android.gms.auth.api.identity.SignInClient;
24
- import com.google.android.gms.auth.api.signin.GoogleSignIn;
25
- import com.google.android.gms.auth.api.signin.GoogleSignInClient;
26
- import com.google.android.gms.auth.api.signin.GoogleSignInOptions;
23
+ import com.google.android.gms.common.ConnectionResult;
24
+ import com.google.android.gms.common.GoogleApiAvailability;
27
25
  import com.google.android.gms.common.api.ApiException;
28
26
  import com.google.android.gms.tasks.OnCompleteListener;
29
27
  import com.google.android.gms.tasks.Task;
@@ -34,8 +32,6 @@ public class GoogleOneTapAuth extends Plugin {
34
32
 
35
33
  private String androidClientId;
36
34
  private SignInClient oneTapClient;
37
- private CredentialsClient mCredentialsClient;
38
- private GoogleSignInClient mSignInClient;
39
35
  private PluginCall currentPluginCall = null;
40
36
  private ActivityResultLauncher<IntentSenderRequest> googleOneTapSignInActivityResultHandlerIntentSenderRequest;
41
37
  private boolean isSignInInProgress = false;
@@ -49,11 +45,6 @@ public class GoogleOneTapAuth extends Plugin {
49
45
  }
50
46
 
51
47
  oneTapClient = Identity.getSignInClient(this.getActivity());
52
- mCredentialsClient = Credentials.getClient(this.getContext());
53
- // DEFAULT_SIGN_IN scopes are id and profile, see GoogleSignInOptions
54
- var gsoBuilder = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
55
- .requestIdToken(androidClientId);
56
- mSignInClient = GoogleSignIn.getClient(this.getContext(), gsoBuilder.build());
57
48
 
58
49
  googleOneTapSignInActivityResultHandlerIntentSenderRequest = bridge.registerForActivityResult(
59
50
  new ActivityResultContracts.StartIntentSenderForResult(),
@@ -95,6 +86,7 @@ public class GoogleOneTapAuth extends Plugin {
95
86
  }
96
87
 
97
88
  private BeginSignInRequest createBeginSignInRequest(boolean tryAutoLogin) {
89
+
98
90
  return BeginSignInRequest.builder()
99
91
  .setGoogleIdTokenRequestOptions(BeginSignInRequest.GoogleIdTokenRequestOptions.builder()
100
92
  .setSupported(true)
@@ -110,24 +102,32 @@ public class GoogleOneTapAuth extends Plugin {
110
102
  }
111
103
 
112
104
  private void beginSignIn(boolean tryAutoLogin) {
113
- var beginSignInRequest = createBeginSignInRequest(tryAutoLogin);
105
+ var context = this.getContext();
114
106
 
107
+ var beginSignInRequest = createBeginSignInRequest(tryAutoLogin);
115
108
  oneTapClient.beginSignIn(beginSignInRequest)
116
109
  .addOnCompleteListener(new OnCompleteListener<BeginSignInResult>() {
117
110
  @Override
118
111
  public void onComplete(@NonNull Task<BeginSignInResult> task) {
119
112
  if (task.isSuccessful()) {
113
+
120
114
  var result = task.getResult();
121
115
  var intentSender = result.getPendingIntent().getIntentSender();
122
116
  var intentSenderRequest = new IntentSenderRequest.Builder(intentSender).build();
123
117
  googleOneTapSignInActivityResultHandlerIntentSenderRequest.launch(intentSenderRequest);
118
+
124
119
  } else {
125
120
  if (tryAutoLogin) {
126
121
  beginSignIn(false);
127
- }
128
- else {
122
+ } else {
129
123
  Log.e(TAG, "beginSignIn failed", task.getException());
130
124
  var errorMessage = task.getException().toString();
125
+ if (!isGooglePlayServicesAvailable(context)) {
126
+ errorMessage += "\nGooglePlayService is not installed or must be updated.";
127
+ }
128
+ if (errorMessage.contains("Missing Feature{name=auth_api_credentials_begin_sign_in")) {
129
+ errorMessage += "\nGooglePlay is not installed or must be logged in to setup.";
130
+ }
131
131
  if (errorMessage.contains("ApiException: 8")) {
132
132
  errorMessage += "\nOne reason for the exception is when the device has no internet.";
133
133
  }
@@ -139,6 +139,12 @@ public class GoogleOneTapAuth extends Plugin {
139
139
  });
140
140
  }
141
141
 
142
+ private boolean isGooglePlayServicesAvailable(Context context) {
143
+ var googleApiAvailability = GoogleApiAvailability.getInstance();
144
+ int resultCode = googleApiAvailability.isGooglePlayServicesAvailable(context);
145
+ return resultCode == ConnectionResult.SUCCESS;
146
+ }
147
+
142
148
  @PluginMethod()
143
149
  public void signOut(final PluginCall call) {
144
150
  oneTapClient.signOut()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "capacitor-native-google-one-tap-signin",
3
- "version": "0.0.21",
3
+ "version": "0.0.22",
4
4
  "description": "Google One Tap sign-in plugin for capacitor.",
5
5
  "main": "dist/esm/index.js",
6
6
  "types": "dist/esm/index.d.ts",
@@ -14,15 +14,15 @@
14
14
  "author": "David Neuy",
15
15
  "license": "MIT",
16
16
  "devDependencies": {
17
- "@capacitor/android": "^4.0.1",
18
- "@capacitor/cli": "^4.0.1",
19
- "@capacitor/core": "^4.0.1",
20
- "@capacitor/ios": "^4.0.1",
17
+ "@capacitor/android": "^4.6.2",
18
+ "@capacitor/cli": "^4.6.2",
19
+ "@capacitor/core": "^4.6.2",
20
+ "@capacitor/ios": "^4.6.2",
21
21
  "@ionic/prettier-config": "^2.0.0",
22
- "@types/gapi": "0.0.42",
23
- "@types/gapi.auth2": "0.0.56",
24
- "prettier": "^2.7.1",
25
- "typescript": "^4.7.4"
22
+ "@types/gapi": "^0.0.44",
23
+ "@types/gapi.auth2": "^0.0.57",
24
+ "prettier": "^2.8.3",
25
+ "typescript": "^4.9.5"
26
26
  },
27
27
  "peerDependencies": {
28
28
  "@capacitor/core": "^4"