capacitor-native-google-one-tap-signin 0.5.0 → 0.5.2

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
@@ -13,7 +13,7 @@ After a successful authentication, the idToken is returned as base64 and as obje
13
13
 
14
14
  The user is automatically signed-in, without a prompt after the first sign-in.
15
15
 
16
- The andorid minSdkVersion is 24, however the one-tap library seems to require API version 29. For lower API versions GoogleSignIn is used.
16
+ The android minSdkVersion is 24, however the one-tap library seems to require API version 29. For lower API versions GoogleSignIn is used.
17
17
 
18
18
  # Install and Configure
19
19
 
@@ -30,11 +30,15 @@ npx cap update
30
30
  ```
31
31
 
32
32
  #### 3. Configure
33
- You need to provide the plug-in a client ID of type "Web application". This client ID is used for the web and android platforms. The client ID is passed in the `initialize` call.
33
+ Authentication is based on cryptographic keys, so you need to create a client ID for each platform in [Google Cloud Console](https://console.cloud.google.com/apis/dashboard).
34
34
 
35
- For the android platform, you need to create a client ID of type "Android" in the [Google Cloud Console](https://console.cloud.google.com/apis/dashboard), as stated in [One Tap Get started docu](https://developers.google.cn/identity/one-tap/android/get-started). You just need to create that client ID, you do not need to include it in any config.
36
35
 
37
- For the ios platform, you need to create a client ID of type iOS in the [Google Cloud Console](https://console.cloud.google.com/apis/dashboard). Add the client ID to the `{your-app}/ios/App/App/Info.plist` file with the key `GIDClientID` (see the demo app for reference). When creating the client ID, you will see the "iOS URL scheme" value in the Google Cloud Console. Add this also to the `Info.plist` file.
36
+ - For the web platform, you need to create a client ID of type "Web application". When creating the client ID for development add two "Authorized JavaScript origins". One with URI "http://localhost:3000" and one with URI "http://localhost". "Authorized redirect URIs" is not needed. Copy the generated client ID and pass it in the `initialize` call. Note that if you host the app not on localhost or on a different port, you will either need to add more origins or add another client ID.
37
+ If you get the error `[GSI_LOGGER]: The given origin is not allowed for the given client ID.` even though you have set the origin, you should check the headers that your server sets. Requests from the iFrame created by the google library must include the origin header. The browser will only set the header for requests from an iFrame if your server does *not* set the `Referrer-Policy` header to `same-origin`. Configure your server to not set the header. Additionally it may be needed that your server responds with a `Cross-Origin-Opener-Policy` header value of `same-origin-allow-popups`.
38
+
39
+ - For the android platform, you need to create a client ID of type "Android", as stated in [One Tap Get started docu](https://developers.google.cn/identity/one-tap/android/get-started). You just need to create that client ID, you do not need to include it in any config. It is linked to your app via the package name and SHA-1 signing certificate fingerprint of your app. Note that usually the signing certificate for developments builds is different than for app store builds so you will need to create a client ID for development builds and one for app store builds.
40
+
41
+ - For the ios platform, you need to create a client ID of type iOS in the [Google Cloud Console](https://console.cloud.google.com/apis/dashboard). Add the client ID to the `{your-app}/ios/App/App/Info.plist` file with the key `GIDClientID` (see the demo app for reference). When creating the client ID, you will see the "iOS URL scheme" value in the Google Cloud Console. Add this also to the `Info.plist` file.
38
42
 
39
43
  # Usage
40
44
 
@@ -44,11 +48,13 @@ import { GoogleOneTapAuth, SignInResult } from 'capacitor-native-google-one-tap-
44
48
  await GoogleOneTapAuth.initialize({ clientId: clientId });
45
49
 
46
50
  // Example 1: Showing the button only if auto-sign-in or one-tap sign in fail.
47
- const signInResult = await GoogleOneTapAuth.tryAutoOrOneTapSignIn().then(res => res.signInResultOptionPromise);
51
+ const signInResult = await GoogleOneTapAuth.tryAutoOrOneTapSignIn()
52
+ .then(res => res.signInResultOptionPromise);
48
53
  if (signInResult.isSuccess) {
49
54
  console.log(signInResult);
50
55
  } else { 
51
- const successResult = await GoogleOneTapAuth.renderSignInButton('appleid-signin', {}, { locale: 'en-US', theme: 'outline', text: 'continue_with', shape: 'rectangular' });
56
+ const successResult = await GoogleOneTapAuth
57
+ .renderSignInButton('google-signin', {}, { text: 'continue_with' });
52
58
  console.log(successResult);
53
59
  }
54
60
 
@@ -61,8 +67,10 @@ import { GoogleOneTapAuth, SignInResult } from 'capacitor-native-google-one-tap-
61
67
  await GoogleOneTapAuth.initialize({ clientId: clientId });
62
68
 
63
69
  // Example 2: Trigger auto-sign-in or one-tap sign and show the button in parallel.
64
- const autoOrOneTapSuccessPromise = GoogleOneTapAuth.tryAutoOrOneTapSignIn().then(res => res.successPromise);
65
- const renderButtonPromise = GoogleOneTapAuth.renderSignInButton('appleid-signin', {}, { locale: 'en-US', theme: 'outline', text: 'continue_with', shape: 'rectangular' });
70
+ const autoOrOneTapSuccessPromise = GoogleOneTapAuth.tryAutoOrOneTapSignIn()
71
+ .then(res => res.successPromise);
72
+ const renderButtonPromise = GoogleOneTapAuth
73
+ .renderSignInButton('google-signin', {}, { text: 'continue_with' });
66
74
  const signInResultSuccess = await Promise.race([autoOrOneTapSuccessPromise, renderButtonPromise]);
67
75
  console.log(signInResultSuccess);
68
76
 
@@ -94,13 +102,23 @@ See `src/definitions.ts` for a complete definition.
94
102
  initialize(options: InitializeOptions): Promise<void>;
95
103
  /**
96
104
  * Tries to either auto-sign-in the user or sign-in the user with just one tap/click.
97
- * If there is a single google account and that account has previously signed into the app, then that user is auto signed in. A short popover is displayed during sign-in.
98
- * If there are multiple google accounts and more than one have previously signed into the app then a user selection screen is shown.
99
- * If there is no active google session or if no user session has logged in previously in the app or if the user has opt out of One Tap, then the response will indicate that the auto sign-in did not succeed.
105
+ * If there is a single google account and that account has previously signed into the app,
106
+ * then that user is auto signed in. A short popover is displayed during sign-in.
107
+ * If there are multiple google accounts and more than one have previously signed into the
108
+ * app then a user selection screen is shown.
109
+ * If there is no active google session or if no user session has logged in previously in
110
+ * the app or if the user has opt out of One Tap, then the response will indicate that
111
+ * the auto sign-in did not succeed.
100
112
  * See https://developers.google.com/identity/gsi/web/guides/features
101
- * @returns A Promise object that contains 3 properties with promises. One resolves only when authentication succeeds, the second on error and the third on success or error.
113
+ * @returns A Promise object that contains 3 properties with promises. One resolves only
114
+ * when authentication succeeds, the second on error and the third on success or error.
102
115
  */
103
- tryAutoOrOneTapSignIn(): Promise<SignInResultPromises>;
116
+ tryAutoOrOneTapSignIn()
117
+ : Promise<{
118
+ successPromise: Promise<SuccessSignInResult>;
119
+ noSuccess: Promise<NoSuccessSignInResult>;
120
+ signInResultOptionPromise: Promise<SignInResultOption>;
121
+ }>;
104
122
  /**
105
123
  * Renders the sign-in button.
106
124
  * The returned promise will only resolve if successful.
@@ -108,14 +126,18 @@ tryAutoOrOneTapSignIn(): Promise<SignInResultPromises>;
108
126
  * @param options
109
127
  * @param gsiButtonConfiguration Not all button configuration options are supported on android.
110
128
  */
111
- renderSignInButton(parentElementId: string, options: RenderSignInButtonOptions, gsiButtonConfiguration?: google.GsiButtonConfiguration): Promise<SuccessSignInResult>;
129
+ renderSignInButton(
130
+ parentElementId: string,
131
+ options: RenderSignInButtonOptions,
132
+ gsiButtonConfiguration?: google.GsiButtonConfiguration): Promise<SuccessSignInResult>;
112
133
  /**
113
134
  * Ends the session.
114
135
  */
115
136
  signOut(): Promise<SignOutResult>;
116
137
  /**
117
138
  * Gets the last user defined or auto-created nonce.
118
- * Unfortunately not all google libraries support setting a nonce, so this is currently not universally useful.
139
+ * Unfortunately not all google libraries support setting a nonce, so this is currently
140
+ * not universally useful.
119
141
  */
120
142
  getNonce(): string;
121
143
 
@@ -115,7 +115,6 @@ public class GoogleOneTapAuth extends Plugin {
115
115
  public void triggerGoogleSignIn(PluginCall call) {
116
116
  try {
117
117
  var signInResult = googleSignIn(call).get();
118
- assert(signInResult.has("idToken") && signInResult.getString("idToken").length() > 0);
119
118
  call.resolve(signInResult);
120
119
  } catch (ExecutionException | InterruptedException e) {
121
120
  call.reject(e.toString());
@@ -247,7 +246,7 @@ public class GoogleOneTapAuth extends Plugin {
247
246
  private Future<JSObject> googleSilentSignIn(final PluginCall call) {
248
247
  googleSignInFuture = new CompletableFuture<>();
249
248
  googleSignInClient.silentSignIn()
250
- .addOnCompleteListener(task -> handleGoogleSignInResult(call, task, false,"silentSignIn"));
249
+ .addOnCompleteListener(task -> handleGoogleSignInResult(call, task, "silentSignIn"));
251
250
  return googleSignInFuture;
252
251
  }
253
252
 
@@ -265,11 +264,11 @@ public class GoogleOneTapAuth extends Plugin {
265
264
  }
266
265
  Intent data = result.getData();
267
266
  var task = GoogleSignIn.getSignedInAccountFromIntent(data);
268
- handleGoogleSignInResult(call, task, true, "GoogleSignInClient.getSignInIntent");
267
+ handleGoogleSignInResult(call, task, "GoogleSignInClient.getSignInIntent");
269
268
  }
270
269
 
271
270
  private void handleGoogleSignInResult(PluginCall call, Task<GoogleSignInAccount> completedTask,
272
- boolean completeFutureOnlyOnSuccess, String triggerMethodName) {
271
+ String triggerMethodName) {
273
272
  try {
274
273
  var account = completedTask.getResult(ApiException.class);
275
274
  signInMethod = SignInMethod.GoogleSignIn;
@@ -279,13 +278,11 @@ public class GoogleOneTapAuth extends Plugin {
279
278
  int statusCode = e.getStatusCode();
280
279
  var statusCodeString = GoogleSignInStatusCodes.getStatusCodeString(statusCode);
281
280
  Log.i(TAG, triggerMethodName + " not successful, statusCodeString " + statusCodeString, e);
282
- if (!completeFutureOnlyOnSuccess) {
283
- if (statusCode == GoogleSignInStatusCodes.SIGN_IN_REQUIRED
284
- || statusCode == GoogleSignInStatusCodes.SIGN_IN_CANCELLED) {
285
- googleSignInFuture.complete(createErrorResponse(statusCodeString, null));
286
- } else {
287
- googleSignInFuture.completeExceptionally(e);
288
- }
281
+ if (statusCode == GoogleSignInStatusCodes.SIGN_IN_REQUIRED
282
+ || statusCode == GoogleSignInStatusCodes.SIGN_IN_CANCELLED) {
283
+ googleSignInFuture.complete(createErrorResponse(statusCodeString, null));
284
+ } else {
285
+ googleSignInFuture.completeExceptionally(e);
289
286
  }
290
287
  }
291
288
  }
package/dist/docs.json CHANGED
@@ -30,18 +30,20 @@
30
30
  },
31
31
  {
32
32
  "name": "tryAutoOrOneTapSignIn",
33
- "signature": "() => Promise<SignInResultPromises>",
33
+ "signature": "() => Promise<{ successPromise: Promise<SuccessSignInResult>; noSuccess: Promise<NoSuccessSignInResult>; signInResultOptionPromise: Promise<SignInResultOption>; }>",
34
34
  "parameters": [],
35
- "returns": "Promise<SignInResultPromises>",
35
+ "returns": "Promise<{ successPromise: Promise<SuccessSignInResult>; noSuccess: Promise<NoSuccessSignInResult>; signInResultOptionPromise: Promise<SignInResultOption>; }>",
36
36
  "tags": [
37
37
  {
38
38
  "name": "returns",
39
- "text": "A Promise object that contains 3 properties with promises. One resolves only when authentication succeeds, the second on error and the third on success or error."
39
+ "text": "A Promise object that contains 3 properties with promises. One resolves only \nwhen authentication succeeds, the second on error and the third on success or error."
40
40
  }
41
41
  ],
42
- "docs": "Tries to either auto-sign-in the user or sign-in the user with just one tap/click.\nIf there is a single google account and that account has previously signed into the app, then that user is auto signed in. A short popover is displayed during sign-in.\nIf there are multiple google accounts and more than one have previously signed into the app then a user selection screen is shown.\nIf there is no active google session or if no user session has logged in previously in the app or if the user has opt out of One Tap, then the response will indicate that the auto sign-in did not succeed.\nSee https://developers.google.com/identity/gsi/web/guides/features",
42
+ "docs": "Tries to either auto-sign-in the user or sign-in the user with just one tap/click.\nIf there is a single google account and that account has previously signed into the app, \nthen that user is auto signed in. A short popover is displayed during sign-in.\nIf there are multiple google accounts and more than one have previously signed into the \napp then a user selection screen is shown.\nIf there is no active google session or if no user session has logged in previously in \nthe app or if the user has opt out of One Tap, then the response will indicate that \nthe auto sign-in did not succeed.\nSee https://developers.google.com/identity/gsi/web/guides/features",
43
43
  "complexTypes": [
44
- "SignInResultPromises"
44
+ "SuccessSignInResult",
45
+ "NoSuccessSignInResult",
46
+ "SignInResultOption"
45
47
  ],
46
48
  "slug": "tryautooronetapsignin"
47
49
  },
@@ -106,7 +108,7 @@
106
108
  "parameters": [],
107
109
  "returns": "string",
108
110
  "tags": [],
109
- "docs": "Gets the last user defined or auto-created nonce.\nUnfortunately not all google libraries support setting a nonce, so this is currently not universally useful.",
111
+ "docs": "Gets the last user defined or auto-created nonce.\nUnfortunately not all google libraries support setting a nonce, so this is currently \nnot universally useful.",
110
112
  "complexTypes": [],
111
113
  "slug": "getnonce"
112
114
  }
@@ -131,48 +133,12 @@
131
133
  {
132
134
  "name": "nonce",
133
135
  "tags": [],
134
- "docs": "A string that is included in the ID token if supported. It is auto-generated if not provided.\nThe com.google.android.gms.auth.api.identity api supports nonce, however the com.google.android.gms.auth.api.signin does currently not, and for ios there is an open issue.\nSee https://github.com/google/GoogleSignIn-iOS/issues/135",
136
+ "docs": "A string that is included in the ID token if supported. It is auto-generated if not provided.\nThe com.google.android.gms.auth.api.identity api supports nonce, however the \ncom.google.android.gms.auth.api.signin does currently not, and for ios there is an open issue.\nSee https://github.com/google/GoogleSignIn-iOS/issues/135",
135
137
  "complexTypes": [],
136
138
  "type": "string | undefined"
137
139
  }
138
140
  ]
139
141
  },
140
- {
141
- "name": "SignInResultPromises",
142
- "slug": "signinresultpromises",
143
- "docs": "",
144
- "tags": [],
145
- "methods": [],
146
- "properties": [
147
- {
148
- "name": "successPromise",
149
- "tags": [],
150
- "docs": "",
151
- "complexTypes": [
152
- "SuccessSignInResult"
153
- ],
154
- "type": "Promise<SuccessSignInResult>"
155
- },
156
- {
157
- "name": "noSuccess",
158
- "tags": [],
159
- "docs": "",
160
- "complexTypes": [
161
- "NoSuccessSignInResult"
162
- ],
163
- "type": "Promise<NoSuccessSignInResult>"
164
- },
165
- {
166
- "name": "signInResultOptionPromise",
167
- "tags": [],
168
- "docs": "",
169
- "complexTypes": [
170
- "SignInResultOption"
171
- ],
172
- "type": "Promise<SignInResultOption>"
173
- }
174
- ]
175
- },
176
142
  {
177
143
  "name": "SuccessSignInResult",
178
144
  "slug": "successsigninresult",
@@ -49,8 +49,10 @@ class GoogleOneTapAuth {
49
49
  assert(() => !!parentElem);
50
50
  return new Promise((resolve) => {
51
51
  const onClickAction = async () => {
52
- const signInResult = await GoogleOneTapAuthPlatform.triggerGoogleSignIn(options);
53
- resolve(signInResult);
52
+ let signInResult = await GoogleOneTapAuthPlatform.triggerGoogleSignIn(options);
53
+ if (Boolean(signInResult.idToken)) {
54
+ resolve(signInResult);
55
+ }
54
56
  };
55
57
  parentElem.appendChild(this._getSignInButtonHtml(onClickAction));
56
58
  });
@@ -1 +1 @@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;QACpE,CAAC,CAAC,CAAC;IACL,CAAC;IAED,QAAQ;QACN,MAAM,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,+BAA+B,GAAG,EAAE,CAAC,IAAI,CAAC,UAAU,cAAc,CAAC,CAAC;QAC/F,OAAO,IAAI,CAAC,KAAM,CAAC;IACrB,CAAC;IAED,oBAAoB,CAAC,aAAwB;QAC3C,kEAAkE;QAClE,MAAM,MAAM,GAAG,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;QAChD,MAAM,CAAC,YAAY,CAAC,OAAO,EAAE,wUAAwU,CAAC,CAAC;QACvW,MAAM,CAAC,OAAO,GAAG,aAAa,CAAC;QAC/B,MAAM,CAAC,SAAS,GAAG;;;;;;;;;;;;;;aAcV,CAAC;QACV,OAAO,MAAM,CAAC;IAChB,CAAC;CACF;AAED,MAAM,gBAAgB,GAAG,IAAI,gBAAgB,EAAE,CAAC;AAChD,OAAO,EAAE,gBAAgB,IAAI,gBAAgB,EAAE,CAAA","sourcesContent":["import { Capacitor, registerPlugin } from '@capacitor/core';\nimport type { InitializeOptions, GoogleOneTapAuthPlugin, SignInResultPromises, SuccessSignInResult, SignOutResult, RenderSignInButtonOptions, NoSuccessSignInResult } from './definitions';\nimport { assert, randomHexString } from './helpers';\nimport { GoogleOneTapAuthWeb } from './web';\n\nconst GoogleOneTapAuthPlatform = registerPlugin<GoogleOneTapAuthWeb>('GoogleOneTapAuth', {\n web: () => new GoogleOneTapAuthWeb(),\n});\n\n// This file is the entry point for all plugin methods. It contains common logic to web, android, iOS or delegates to the specific implementation.\nclass GoogleOneTapAuth implements GoogleOneTapAuthPlugin {\n nonce?: string;\n isInitialized = false;\n\n async initialize(options: InitializeOptions): Promise<void> {\n if (!options.clientId || options.clientId.endsWith(\"apps.googleusercontent.com\") == false) {\n throw new Error(\"clientId must end with 'apps.googleusercontent.com' but is: \" + options.clientId);\n }\n this.nonce = options.nonce = options.nonce || randomHexString(10);\n await GoogleOneTapAuthPlatform.initialize(options);\n this.isInitialized = true;\n }\n\n async tryAutoOrOneTapSignIn(): Promise<SignInResultPromises> {\n assert(() => this.isInitialized, 'Must call and await initialize first.');\n const signInResultOptionPromise = GoogleOneTapAuthPlatform.tryAutoOrOneTapSignIn();\n let signInResultOption = await signInResultOptionPromise;\n\n if (signInResultOption.isSuccess) {\n return {\n successPromise: Promise.resolve(signInResultOption.success!),\n noSuccess: new Promise<NoSuccessSignInResult>(() => {}),\n signInResultOptionPromise: signInResultOptionPromise\n };\n } else {\n return {\n successPromise: new Promise<SuccessSignInResult>(() => {}),\n noSuccess: Promise.resolve(signInResultOption.noSuccess!),\n signInResultOptionPromise: signInResultOptionPromise\n };\n }\n }\n\n signOut(): Promise<SignOutResult> {\n return GoogleOneTapAuthPlatform.signOut();\n }\n \n renderSignInButton(parentElementId: string, options: RenderSignInButtonOptions, gsiButtonConfiguration?: google.GsiButtonConfiguration): Promise<SuccessSignInResult> {\n assert(() => this.isInitialized, 'Must call and await initialize first.');\n options.webOptions = options.webOptions || {};\n if (Capacitor.getPlatform() === 'web') {\n return GoogleOneTapAuthPlatform.renderSignInButton(parentElementId, options, gsiButtonConfiguration);\n }\n const parentElem = document.getElementById(parentElementId);\n assert(() => !!parentElem);\n return new Promise<SuccessSignInResult>((resolve) => {\n const onClickAction = async () => {\n const signInResult = await (GoogleOneTapAuthPlatform as any).triggerGoogleSignIn(options);\n resolve(signInResult);\n };\n parentElem!.appendChild(this._getSignInButtonHtml(onClickAction));\n });\n }\n\n getNonce() {\n assert(() => !!this.nonce, `The nonce is only set after ${() => this.initialize} was called.`);\n return this.nonce!;\n }\n\n _getSignInButtonHtml(onClickAction: () => any) {\n // HTML from https://github.com/inouiw/ReactSignInWithGoogleButton\n const button = document.createElement('button');\n button.setAttribute(\"style\", \"border-radius: 4px; background-color: rgb(255, 255, 255); border: 1px solid rgb(218, 220, 224); color: rgb(60, 64, 67); cursor: pointer; font-family: Roboto; font-weight: 500; font-size: 14px; height: 40px; letter-spacing: 0.25px; padding: 0px 12px; position: relative; text-align: center; vertical-align: middle; width: auto;\");\n button.onclick = onClickAction;\n button.innerHTML = `\n <div style=\"display: flex; align-items: center; flex-flow: row nowrap; justify-content: space-between; height: 100%; position: relative; width: 100%;\">\n <div style=\"height: 18px; margin-right: 8px; min-width: 18px; width: 18px;\">\n <svg version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\" width=\"18px\" height=\"18px\" viewBox=\"0 0 48 48\">\n <g>\n <path fill=\"#EA4335\" d=\"M24 9.5c3.54 0 6.71 1.22 9.21 3.6l6.85-6.85C35.9 2.38 30.47 0 24 0 14.62 0 6.51 5.38 2.56 13.22l7.98 6.19C12.43 13.72 17.74 9.5 24 9.5z\"></path>\n <path fill=\"#4285F4\" d=\"M46.98 24.55c0-1.57-.15-3.09-.38-4.55H24v9.02h12.94c-.58 2.96-2.26 5.48-4.78 7.18l7.73 6c4.51-4.18 7.09-10.36 7.09-17.65z\"></path>\n <path fill=\"#FBBC05\" d=\"M10.53 28.59c-.48-1.45-.76-2.99-.76-4.59s.27-3.14.76-4.59l-7.98-6.19C.92 16.46 0 20.12 0 24c0 3.88.92 7.54 2.56 10.78l7.97-6.19z\"></path>\n <path fill=\"#34A853\" d=\"M24 48c6.48 0 11.93-2.13 15.89-5.81l-7.73-6c-2.15 1.45-4.92 2.3-8.16 2.3-6.26 0-11.57-4.22-13.47-9.91l-7.98 6.19C6.51 42.62 14.62 48 24 48z\"></path>\n <path fill=\"none\" d=\"M0 0h48v48H0z\"></path>\n </g>\n </svg>\n </div>\n <p>Sign in with Google</p>\n </div>`;\n return button;\n }\n}\n\nconst googleOneTapAuth = new GoogleOneTapAuth();\nexport { googleOneTapAuth as GoogleOneTapAuth }"]}
1
+ {"version":3,"file":"GoogleOneTapAuth.js","sourceRoot":"","sources":["../../src/GoogleOneTapAuth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,iBAAiB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,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,+BAA+B,GAAG,EAAE,CAAC,IAAI,CAAC,UAAU,cAAc,CAAC,CAAC;QAC/F,OAAO,IAAI,CAAC,KAAM,CAAC;IACrB,CAAC;IAED,oBAAoB,CAAC,aAAwB;QAC3C,kEAAkE;QAClE,MAAM,MAAM,GAAG,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;QAChD,MAAM,CAAC,YAAY,CAAC,OAAO,EAAE,wUAAwU,CAAC,CAAC;QACvW,MAAM,CAAC,OAAO,GAAG,aAAa,CAAC;QAC/B,MAAM,CAAC,SAAS,GAAG;;;;;;;;;;;;;;aAcV,CAAC;QACV,OAAO,MAAM,CAAC;IAChB,CAAC;CACF;AAED,MAAM,gBAAgB,GAAG,IAAI,gBAAgB,EAAE,CAAC;AAChD,OAAO,EAAE,gBAAgB,IAAI,gBAAgB,EAAE,CAAA","sourcesContent":["import { Capacitor, registerPlugin } from '@capacitor/core';\nimport type { InitializeOptions, GoogleOneTapAuthPlugin, SignInResultPromises, SuccessSignInResult, SignOutResult, RenderSignInButtonOptions, NoSuccessSignInResult } from './definitions';\nimport { assert, randomHexString } from './helpers';\nimport { GoogleOneTapAuthWeb } from './web';\n\nconst GoogleOneTapAuthPlatform = registerPlugin<GoogleOneTapAuthWeb>('GoogleOneTapAuth', {\n web: () => new GoogleOneTapAuthWeb(),\n});\n\n// This file is the entry point for all plugin methods. It contains common logic to web, android, iOS or delegates to the specific implementation.\nclass GoogleOneTapAuth implements GoogleOneTapAuthPlugin {\n nonce?: string;\n isInitialized = false;\n\n async initialize(options: InitializeOptions): Promise<void> {\n if (!options.clientId || options.clientId.endsWith(\"apps.googleusercontent.com\") == false) {\n throw new Error(\"clientId must end with 'apps.googleusercontent.com' but is: \" + options.clientId);\n }\n this.nonce = options.nonce = options.nonce || randomHexString(10);\n await GoogleOneTapAuthPlatform.initialize(options);\n this.isInitialized = true;\n }\n\n async tryAutoOrOneTapSignIn(): Promise<SignInResultPromises> {\n assert(() => this.isInitialized, 'Must call and await initialize first.');\n const signInResultOptionPromise = GoogleOneTapAuthPlatform.tryAutoOrOneTapSignIn();\n let signInResultOption = await signInResultOptionPromise;\n\n if (signInResultOption.isSuccess) {\n return {\n successPromise: Promise.resolve(signInResultOption.success!),\n noSuccess: new Promise<NoSuccessSignInResult>(() => {}),\n signInResultOptionPromise: signInResultOptionPromise\n };\n } else {\n return {\n successPromise: new Promise<SuccessSignInResult>(() => {}),\n noSuccess: Promise.resolve(signInResultOption.noSuccess!),\n signInResultOptionPromise: signInResultOptionPromise\n };\n }\n }\n\n signOut(): Promise<SignOutResult> {\n return GoogleOneTapAuthPlatform.signOut();\n }\n \n renderSignInButton(parentElementId: string, options: RenderSignInButtonOptions, gsiButtonConfiguration?: google.GsiButtonConfiguration): Promise<SuccessSignInResult> {\n assert(() => this.isInitialized, 'Must call and await initialize first.');\n options.webOptions = options.webOptions || {};\n if (Capacitor.getPlatform() === 'web') {\n return GoogleOneTapAuthPlatform.renderSignInButton(parentElementId, options, gsiButtonConfiguration);\n }\n const parentElem = document.getElementById(parentElementId);\n assert(() => !!parentElem);\n return new Promise<SuccessSignInResult>((resolve) => {\n const onClickAction = async () => {\n let signInResult = await (GoogleOneTapAuthPlatform as any).triggerGoogleSignIn(options);\n if (Boolean(signInResult.idToken)) {\n resolve(signInResult);\n }\n };\n parentElem!.appendChild(this._getSignInButtonHtml(onClickAction));\n });\n }\n\n getNonce() {\n assert(() => !!this.nonce, `The nonce is only set after ${() => this.initialize} was called.`);\n return this.nonce!;\n }\n\n _getSignInButtonHtml(onClickAction: () => any) {\n // HTML from https://github.com/inouiw/ReactSignInWithGoogleButton\n const button = document.createElement('button');\n button.setAttribute(\"style\", \"border-radius: 4px; background-color: rgb(255, 255, 255); border: 1px solid rgb(218, 220, 224); color: rgb(60, 64, 67); cursor: pointer; font-family: Roboto; font-weight: 500; font-size: 14px; height: 40px; letter-spacing: 0.25px; padding: 0px 12px; position: relative; text-align: center; vertical-align: middle; width: auto;\");\n button.onclick = onClickAction;\n button.innerHTML = `\n <div style=\"display: flex; align-items: center; flex-flow: row nowrap; justify-content: space-between; height: 100%; position: relative; width: 100%;\">\n <div style=\"height: 18px; margin-right: 8px; min-width: 18px; width: 18px;\">\n <svg version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\" width=\"18px\" height=\"18px\" viewBox=\"0 0 48 48\">\n <g>\n <path fill=\"#EA4335\" d=\"M24 9.5c3.54 0 6.71 1.22 9.21 3.6l6.85-6.85C35.9 2.38 30.47 0 24 0 14.62 0 6.51 5.38 2.56 13.22l7.98 6.19C12.43 13.72 17.74 9.5 24 9.5z\"></path>\n <path fill=\"#4285F4\" d=\"M46.98 24.55c0-1.57-.15-3.09-.38-4.55H24v9.02h12.94c-.58 2.96-2.26 5.48-4.78 7.18l7.73 6c4.51-4.18 7.09-10.36 7.09-17.65z\"></path>\n <path fill=\"#FBBC05\" d=\"M10.53 28.59c-.48-1.45-.76-2.99-.76-4.59s.27-3.14.76-4.59l-7.98-6.19C.92 16.46 0 20.12 0 24c0 3.88.92 7.54 2.56 10.78l7.97-6.19z\"></path>\n <path fill=\"#34A853\" d=\"M24 48c6.48 0 11.93-2.13 15.89-5.81l-7.73-6c-2.15 1.45-4.92 2.3-8.16 2.3-6.26 0-11.57-4.22-13.47-9.91l-7.98 6.19C6.51 42.62 14.62 48 24 48z\"></path>\n <path fill=\"none\" d=\"M0 0h48v48H0z\"></path>\n </g>\n </svg>\n </div>\n <p>Sign in with Google</p>\n </div>`;\n return button;\n }\n}\n\nconst googleOneTapAuth = new GoogleOneTapAuth();\nexport { googleOneTapAuth as GoogleOneTapAuth }"]}
@@ -5,7 +5,8 @@ export interface InitializeOptions {
5
5
  clientId: string;
6
6
  /**
7
7
  * A string that is included in the ID token if supported. It is auto-generated if not provided.
8
- * The com.google.android.gms.auth.api.identity api supports nonce, however the com.google.android.gms.auth.api.signin does currently not, and for ios there is an open issue.
8
+ * The com.google.android.gms.auth.api.identity api supports nonce, however the
9
+ * com.google.android.gms.auth.api.signin does currently not, and for ios there is an open issue.
9
10
  * See https://github.com/google/GoogleSignIn-iOS/issues/135
10
11
  */
11
12
  nonce?: string;
@@ -95,13 +96,22 @@ export interface GoogleOneTapAuthPlugin {
95
96
  initialize(options: InitializeOptions): Promise<void>;
96
97
  /**
97
98
  * Tries to either auto-sign-in the user or sign-in the user with just one tap/click.
98
- * If there is a single google account and that account has previously signed into the app, then that user is auto signed in. A short popover is displayed during sign-in.
99
- * If there are multiple google accounts and more than one have previously signed into the app then a user selection screen is shown.
100
- * If there is no active google session or if no user session has logged in previously in the app or if the user has opt out of One Tap, then the response will indicate that the auto sign-in did not succeed.
99
+ * If there is a single google account and that account has previously signed into the app,
100
+ * then that user is auto signed in. A short popover is displayed during sign-in.
101
+ * If there are multiple google accounts and more than one have previously signed into the
102
+ * app then a user selection screen is shown.
103
+ * If there is no active google session or if no user session has logged in previously in
104
+ * the app or if the user has opt out of One Tap, then the response will indicate that
105
+ * the auto sign-in did not succeed.
101
106
  * See https://developers.google.com/identity/gsi/web/guides/features
102
- * @returns A Promise object that contains 3 properties with promises. One resolves only when authentication succeeds, the second on error and the third on success or error.
107
+ * @returns A Promise object that contains 3 properties with promises. One resolves only
108
+ * when authentication succeeds, the second on error and the third on success or error.
103
109
  */
104
- tryAutoOrOneTapSignIn(): Promise<SignInResultPromises>;
110
+ tryAutoOrOneTapSignIn(): Promise<{
111
+ successPromise: Promise<SuccessSignInResult>;
112
+ noSuccess: Promise<NoSuccessSignInResult>;
113
+ signInResultOptionPromise: Promise<SignInResultOption>;
114
+ }>;
105
115
  /**
106
116
  * Renders the sign-in button.
107
117
  * The returned promise will only resolve if successful.
@@ -116,7 +126,8 @@ export interface GoogleOneTapAuthPlugin {
116
126
  signOut(): Promise<SignOutResult>;
117
127
  /**
118
128
  * Gets the last user defined or auto-created nonce.
119
- * Unfortunately not all google libraries support setting a nonce, so this is currently not universally useful.
129
+ * Unfortunately not all google libraries support setting a nonce, so this is currently
130
+ * not universally useful.
120
131
  */
121
132
  getNonce(): string;
122
133
  }
@@ -1 +1 @@
1
- {"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"AAAA,wCAAwC","sourcesContent":["/// <reference types=\"@capacitor/cli\" />\n\nexport interface InitializeOptions {\n /**\n * Your client ID of type Web application.\n */\n clientId: string;\n /**\n * A string that is included in the ID token if supported. It is auto-generated if not provided.\n * The com.google.android.gms.auth.api.identity api supports nonce, however the com.google.android.gms.auth.api.signin does currently not, and for ios there is an open issue.\n * See https://github.com/google/GoogleSignIn-iOS/issues/135\n */\n nonce?: string;\n}\n\nexport interface SignInResultPromises {\n successPromise: Promise<SuccessSignInResult>;\n noSuccess: Promise<NoSuccessSignInResult>;\n signInResultOptionPromise: Promise<SignInResultOption>;\n}\n\nexport interface SignInResultOption {\n /**\n * Indicates if the success or noSuccess property is set.\n */\n isSuccess: boolean;\n /**\n * Success result.\n */\n success?: SuccessSignInResult;\n /**\n * NoSuccess result.\n */\n noSuccess?: NoSuccessSignInResult;\n}\n\nexport interface SuccessSignInResult {\n /**\n * How the credential was retrieved.\n * Currently not available for android, only if the js library is used.\n * For possible values see google.PromptMomentNotification.\n */\n selectBy?: \n | 'auto'\n | 'user'\n | 'user_1tap'\n | 'user_2tap'\n | 'btn'\n | 'btn_confirm'\n | 'btn_add_session'\n | 'btn_confirm_add_session' // see google.CredentialResponse.select_by\n /**\n * The JWT token base64 encoded.\n */\n idToken: string;\n /**\n * A permanent id for the user.\n */\n userId: string;\n /**\n * The email address.\n */\n email: string;\n /**\n * The decoded JWT token.\n * The signature is not verified when decoding the token.\n */\n decodedIdToken: any;\n}\n\nexport interface NoSuccessSignInResult {\n /**\n * A reason code as 'opt_out_or_no_session'.\n * For the js library see google.PromptMomentNotification for possible values.\n * For android 'SIGN_IN_REQUIRED' and 'SIGN_IN_CANCELLED' are currently set.\n */\n noSuccessReasonCode?: string;\n /**\n * A error message.\n * Set in case of error if the native android code is used.\n */\n noSuccessAdditionalInfo?: string;\n}\n\nexport interface RenderSignInButtonOptions {\n /**\n * \tWeb platform specific options..\n */\n webOptions?: RenderSignInButtonWebOptions;\n}\n\nexport interface RenderSignInButtonWebOptions {\n /**\n * \tEnables upgraded One Tap UX on ITP browsers. The default value is false.\n */\n itpSupport?: boolean;\n /**\n * \tThe Sign In With Google button UX flow. The default value is 'popup'.\n */\n uxMode?: 'popup' | 'redirect';\n}\n\nexport interface SignOutResult {\n isSuccess: boolean;\n error?: string;\n}\n\nexport interface GoogleOneTapAuthPlugin {\n /**\n * For the web platform, starts pre-loading the google one tap JavaScript library.\n * @param options \n */\n initialize(options: InitializeOptions): Promise<void>;\n /**\n * Tries to either auto-sign-in the user or sign-in the user with just one tap/click.\n * If there is a single google account and that account has previously signed into the app, then that user is auto signed in. A short popover is displayed during sign-in.\n * If there are multiple google accounts and more than one have previously signed into the app then a user selection screen is shown.\n * If there is no active google session or if no user session has logged in previously in the app or if the user has opt out of One Tap, then the response will indicate that the auto sign-in did not succeed.\n * See https://developers.google.com/identity/gsi/web/guides/features\n * @returns A Promise object that contains 3 properties with promises. One resolves only when authentication succeeds, the second on error and the third on success or error.\n */\n tryAutoOrOneTapSignIn(): Promise<SignInResultPromises>;\n /**\n * Renders the sign-in button.\n * The returned promise will only resolve if successful.\n * @param parentElementId \n * @param options \n * @param gsiButtonConfiguration Not all button configuration options are supported on android.\n */\n renderSignInButton(parentElementId: string, options: RenderSignInButtonOptions, gsiButtonConfiguration?: google.GsiButtonConfiguration): Promise<SuccessSignInResult>;\n /**\n * Ends the session.\n */\n signOut(): Promise<SignOutResult>;\n /**\n * Gets the last user defined or auto-created nonce.\n * Unfortunately not all google libraries support setting a nonce, so this is currently not universally useful.\n */\n getNonce(): string;\n}\n"]}
1
+ {"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"AAAA,wCAAwC","sourcesContent":["/// <reference types=\"@capacitor/cli\" />\n\nexport interface InitializeOptions {\n /**\n * Your client ID of type Web application.\n */\n clientId: string;\n /**\n * A string that is included in the ID token if supported. It is auto-generated if not provided.\n * The com.google.android.gms.auth.api.identity api supports nonce, however the \n * com.google.android.gms.auth.api.signin does currently not, and for ios there is an open issue.\n * See https://github.com/google/GoogleSignIn-iOS/issues/135\n */\n nonce?: string;\n}\n\nexport interface SignInResultPromises {\n successPromise: Promise<SuccessSignInResult>;\n noSuccess: Promise<NoSuccessSignInResult>;\n signInResultOptionPromise: Promise<SignInResultOption>;\n}\n\nexport interface SignInResultOption {\n /**\n * Indicates if the success or noSuccess property is set.\n */\n isSuccess: boolean;\n /**\n * Success result.\n */\n success?: SuccessSignInResult;\n /**\n * NoSuccess result.\n */\n noSuccess?: NoSuccessSignInResult;\n}\n\nexport interface SuccessSignInResult {\n /**\n * How the credential was retrieved.\n * Currently not available for android, only if the js library is used.\n * For possible values see google.PromptMomentNotification.\n */\n selectBy?: \n | 'auto'\n | 'user'\n | 'user_1tap'\n | 'user_2tap'\n | 'btn'\n | 'btn_confirm'\n | 'btn_add_session'\n | 'btn_confirm_add_session' // see google.CredentialResponse.select_by\n /**\n * The JWT token base64 encoded.\n */\n idToken: string;\n /**\n * A permanent id for the user.\n */\n userId: string;\n /**\n * The email address.\n */\n email: string;\n /**\n * The decoded JWT token.\n * The signature is not verified when decoding the token.\n */\n decodedIdToken: any;\n}\n\nexport interface NoSuccessSignInResult {\n /**\n * A reason code as 'opt_out_or_no_session'.\n * For the js library see google.PromptMomentNotification for possible values.\n * For android 'SIGN_IN_REQUIRED' and 'SIGN_IN_CANCELLED' are currently set.\n */\n noSuccessReasonCode?: string;\n /**\n * A error message.\n * Set in case of error if the native android code is used.\n */\n noSuccessAdditionalInfo?: string;\n}\n\nexport interface RenderSignInButtonOptions {\n /**\n * \tWeb platform specific options..\n */\n webOptions?: RenderSignInButtonWebOptions;\n}\n\nexport interface RenderSignInButtonWebOptions {\n /**\n * \tEnables upgraded One Tap UX on ITP browsers. The default value is false.\n */\n itpSupport?: boolean;\n /**\n * \tThe Sign In With Google button UX flow. The default value is 'popup'.\n */\n uxMode?: 'popup' | 'redirect';\n}\n\nexport interface SignOutResult {\n isSuccess: boolean;\n error?: string;\n}\n\nexport interface GoogleOneTapAuthPlugin {\n /**\n * For the web platform, starts pre-loading the google one tap JavaScript library.\n * @param options \n */\n initialize(options: InitializeOptions): Promise<void>;\n /**\n * Tries to either auto-sign-in the user or sign-in the user with just one tap/click.\n * If there is a single google account and that account has previously signed into the app, \n * then that user is auto signed in. A short popover is displayed during sign-in.\n * If there are multiple google accounts and more than one have previously signed into the \n * app then a user selection screen is shown.\n * If there is no active google session or if no user session has logged in previously in \n * the app or if the user has opt out of One Tap, then the response will indicate that \n * the auto sign-in did not succeed.\n * See https://developers.google.com/identity/gsi/web/guides/features\n * @returns A Promise object that contains 3 properties with promises. One resolves only \n * when authentication succeeds, the second on error and the third on success or error.\n */\n tryAutoOrOneTapSignIn()\n : Promise<{\n successPromise: Promise<SuccessSignInResult>;\n noSuccess: Promise<NoSuccessSignInResult>;\n signInResultOptionPromise: Promise<SignInResultOption>;\n }>;\n /**\n * Renders the sign-in button.\n * The returned promise will only resolve if successful.\n * @param parentElementId \n * @param options \n * @param gsiButtonConfiguration Not all button configuration options are supported on android.\n */\n renderSignInButton(\n parentElementId: string,\n options: RenderSignInButtonOptions,\n gsiButtonConfiguration?: google.GsiButtonConfiguration)\n : Promise<SuccessSignInResult>;\n /**\n * Ends the session.\n */\n signOut(): Promise<SignOutResult>;\n /**\n * Gets the last user defined or auto-created nonce.\n * Unfortunately not all google libraries support setting a nonce, so this is currently \n * not universally useful.\n */\n getNonce(): string;\n}\n"]}
@@ -217,8 +217,10 @@ class GoogleOneTapAuth {
217
217
  assert(() => !!parentElem);
218
218
  return new Promise((resolve) => {
219
219
  const onClickAction = async () => {
220
- const signInResult = await GoogleOneTapAuthPlatform.triggerGoogleSignIn(options);
221
- resolve(signInResult);
220
+ let signInResult = await GoogleOneTapAuthPlatform.triggerGoogleSignIn(options);
221
+ if (Boolean(signInResult.idToken)) {
222
+ resolve(signInResult);
223
+ }
222
224
  };
223
225
  parentElem.appendChild(this._getSignInButtonHtml(onClickAction));
224
226
  });
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.cjs.js","sources":["esm/helpers.js","esm/web.js","esm/GoogleOneTapAuth.js"],"sourcesContent":["export function assert(predicate, customMessage) {\n if (!predicate()) {\n if (customMessage != undefined) {\n throw Error(customMessage);\n }\n throw Error(`Assert error, expected '${predicate}' to be true.`);\n }\n}\nexport function randomHexString(length) {\n let uint8RandomNumbers = new Uint8Array((length / 2) + 1);\n uint8RandomNumbers = crypto.getRandomValues(uint8RandomNumbers);\n const numbersAsHexString = Array.from(uint8RandomNumbers).map(x => x.toString(16)).join('');\n return numbersAsHexString.substring(0, length);\n}\n//# sourceMappingURL=helpers.js.map","import { WebPlugin } from '@capacitor/core';\nimport * as scriptjs from 'scriptjs';\nimport jwt_decode from 'jwt-decode';\nimport { assert } from './helpers';\n// See https://developers.google.com/identity/gsi/web/guides/use-one-tap-js-api\nexport class GoogleOneTapAuthWeb extends WebPlugin {\n constructor() {\n super(...arguments);\n this.gsiScriptUrl = 'https://accounts.google.com/gsi/client';\n this.gapiLoadedPromise = undefined;\n this.authenticatedUserId = undefined;\n this.clientId = undefined;\n this.nonce = undefined;\n }\n async initialize(options) {\n this.clientId = options.clientId;\n this.nonce = options.nonce;\n if (!this.gapiLoadedPromise) {\n this.gapiLoadedPromise = new Promise((resolve) => {\n scriptjs.get(this.gsiScriptUrl, () => {\n resolve();\n });\n });\n }\n return this.gapiLoadedPromise;\n }\n async tryAutoOrOneTapSignIn() {\n let signInResult = await this.doSignIn(true);\n if (!signInResult.idToken) {\n signInResult = await this.doSignIn(false);\n }\n if (signInResult.idToken) {\n return {\n isSuccess: true,\n success: signInResult\n };\n }\n else {\n return {\n isSuccess: false,\n noSuccess: signInResult\n };\n }\n }\n async renderSignInButton(parentElementId, options, gsiButtonConfiguration) {\n const parentElem = document.getElementById(parentElementId);\n assert(() => !!parentElem);\n var signInPromise = new Promise((resolve) => {\n this.oneTapInitialize(false, resolve, options.webOptions);\n google.accounts.id.renderButton(parentElem, gsiButtonConfiguration || {});\n });\n return signInPromise;\n }\n async doSignIn(autoSelect) {\n var signInPromise = new Promise((resolve) => {\n this.oneTapInitialize(autoSelect, resolve);\n google.accounts.id.prompt((notification) => {\n if (notification.isNotDisplayed()\n || notification.isSkippedMoment()\n || notification.isDismissedMoment()) {\n resolve({\n noSuccessReasonCode: this.getMomentReason(notification)\n });\n }\n });\n });\n return signInPromise;\n }\n getMomentReason(notification) {\n if (notification.isNotDisplayed()) {\n return notification.getNotDisplayedReason();\n }\n if (notification.isSkippedMoment()) {\n return notification.getSkippedReason();\n }\n if (notification.isDismissedMoment()) {\n return notification.getDismissedReason();\n }\n return undefined;\n }\n oneTapInitialize(autoSelect, resolveSignInFunc, webOptions) {\n google.accounts.id.initialize({\n client_id: this.clientId,\n callback: (credentialResponse) => this.handleCredentialResponse(credentialResponse, resolveSignInFunc),\n auto_select: autoSelect,\n itp_support: (webOptions === null || webOptions === void 0 ? void 0 : webOptions.itpSupport) || false,\n cancel_on_tap_outside: false,\n ux_mode: (webOptions === null || webOptions === void 0 ? void 0 : webOptions.uxMode) || 'popup',\n nonce: this.nonce,\n });\n }\n handleCredentialResponse(credentialResponse, resolveSignInFunc) {\n const decodedIdToken = jwt_decode(credentialResponse.credential);\n let signInResult = {\n idToken: credentialResponse.credential,\n userId: decodedIdToken.sub,\n email: decodedIdToken.email,\n selectBy: credentialResponse.select_by,\n decodedIdToken: decodedIdToken\n };\n this.authenticatedUserId = decodedIdToken['sub'];\n // console.log(decodedIdToken);\n resolveSignInFunc(signInResult);\n }\n signOut() {\n return new Promise((resolve) => {\n google.accounts.id.cancel();\n if (this.authenticatedUserId) {\n // Calling revoke method revokes all OAuth2 scopes previously granted by the Sign In With Google client library.\n google.accounts.id.revoke(this.authenticatedUserId, response => {\n if (response.successful) {\n resolve({ isSuccess: true });\n }\n else {\n resolve({ isSuccess: false, error: response.error });\n }\n });\n this.authenticatedUserId = undefined;\n }\n else {\n resolve({ isSuccess: true });\n }\n });\n }\n getNonce() {\n throw new Error('Should never be called because handled wrapper class.');\n }\n}\n//# sourceMappingURL=web.js.map","import { Capacitor, registerPlugin } from '@capacitor/core';\nimport { assert, randomHexString } from './helpers';\nimport { GoogleOneTapAuthWeb } from './web';\nconst GoogleOneTapAuthPlatform = registerPlugin('GoogleOneTapAuth', {\n web: () => new GoogleOneTapAuthWeb(),\n});\n// This file is the entry point for all plugin methods. It contains common logic to web, android, iOS or delegates to the specific implementation.\nclass GoogleOneTapAuth {\n constructor() {\n this.isInitialized = false;\n }\n async initialize(options) {\n if (!options.clientId || options.clientId.endsWith(\"apps.googleusercontent.com\") == false) {\n throw new Error(\"clientId must end with 'apps.googleusercontent.com' but is: \" + options.clientId);\n }\n this.nonce = options.nonce = options.nonce || randomHexString(10);\n await GoogleOneTapAuthPlatform.initialize(options);\n this.isInitialized = true;\n }\n async tryAutoOrOneTapSignIn() {\n assert(() => this.isInitialized, 'Must call and await initialize first.');\n const signInResultOptionPromise = GoogleOneTapAuthPlatform.tryAutoOrOneTapSignIn();\n let signInResultOption = await signInResultOptionPromise;\n if (signInResultOption.isSuccess) {\n return {\n successPromise: Promise.resolve(signInResultOption.success),\n noSuccess: new Promise(() => { }),\n signInResultOptionPromise: signInResultOptionPromise\n };\n }\n else {\n return {\n successPromise: new Promise(() => { }),\n noSuccess: Promise.resolve(signInResultOption.noSuccess),\n signInResultOptionPromise: signInResultOptionPromise\n };\n }\n }\n signOut() {\n return GoogleOneTapAuthPlatform.signOut();\n }\n renderSignInButton(parentElementId, options, gsiButtonConfiguration) {\n assert(() => this.isInitialized, 'Must call and await initialize first.');\n options.webOptions = options.webOptions || {};\n if (Capacitor.getPlatform() === 'web') {\n return GoogleOneTapAuthPlatform.renderSignInButton(parentElementId, options, gsiButtonConfiguration);\n }\n const parentElem = document.getElementById(parentElementId);\n assert(() => !!parentElem);\n return new Promise((resolve) => {\n const onClickAction = async () => {\n const signInResult = await GoogleOneTapAuthPlatform.triggerGoogleSignIn(options);\n resolve(signInResult);\n };\n parentElem.appendChild(this._getSignInButtonHtml(onClickAction));\n });\n }\n getNonce() {\n assert(() => !!this.nonce, `The nonce is only set after ${() => this.initialize} was called.`);\n return this.nonce;\n }\n _getSignInButtonHtml(onClickAction) {\n // HTML from https://github.com/inouiw/ReactSignInWithGoogleButton\n const button = document.createElement('button');\n button.setAttribute(\"style\", \"border-radius: 4px; background-color: rgb(255, 255, 255); border: 1px solid rgb(218, 220, 224); color: rgb(60, 64, 67); cursor: pointer; font-family: Roboto; font-weight: 500; font-size: 14px; height: 40px; letter-spacing: 0.25px; padding: 0px 12px; position: relative; text-align: center; vertical-align: middle; width: auto;\");\n button.onclick = onClickAction;\n button.innerHTML = `\n <div style=\"display: flex; align-items: center; flex-flow: row nowrap; justify-content: space-between; height: 100%; position: relative; width: 100%;\">\n <div style=\"height: 18px; margin-right: 8px; min-width: 18px; width: 18px;\">\n <svg version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\" width=\"18px\" height=\"18px\" viewBox=\"0 0 48 48\">\n <g>\n <path fill=\"#EA4335\" d=\"M24 9.5c3.54 0 6.71 1.22 9.21 3.6l6.85-6.85C35.9 2.38 30.47 0 24 0 14.62 0 6.51 5.38 2.56 13.22l7.98 6.19C12.43 13.72 17.74 9.5 24 9.5z\"></path>\n <path fill=\"#4285F4\" d=\"M46.98 24.55c0-1.57-.15-3.09-.38-4.55H24v9.02h12.94c-.58 2.96-2.26 5.48-4.78 7.18l7.73 6c4.51-4.18 7.09-10.36 7.09-17.65z\"></path>\n <path fill=\"#FBBC05\" d=\"M10.53 28.59c-.48-1.45-.76-2.99-.76-4.59s.27-3.14.76-4.59l-7.98-6.19C.92 16.46 0 20.12 0 24c0 3.88.92 7.54 2.56 10.78l7.97-6.19z\"></path>\n <path fill=\"#34A853\" d=\"M24 48c6.48 0 11.93-2.13 15.89-5.81l-7.73-6c-2.15 1.45-4.92 2.3-8.16 2.3-6.26 0-11.57-4.22-13.47-9.91l-7.98 6.19C6.51 42.62 14.62 48 24 48z\"></path>\n <path fill=\"none\" d=\"M0 0h48v48H0z\"></path>\n </g>\n </svg>\n </div>\n <p>Sign in with Google</p>\n </div>`;\n return button;\n }\n}\nconst googleOneTapAuth = new GoogleOneTapAuth();\nexport { googleOneTapAuth as GoogleOneTapAuth };\n//# sourceMappingURL=GoogleOneTapAuth.js.map"],"names":["WebPlugin","scriptjs","jwt_decode","registerPlugin","Capacitor"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAO,SAAS,MAAM,CAAC,SAAS,EAAE,aAAa,EAAE;AACjD,IAAI,IAAI,CAAC,SAAS,EAAE,EAAE;AACtB,QAAQ,IAAI,aAAa,IAAI,SAAS,EAAE;AACxC,YAAY,MAAM,KAAK,CAAC,aAAa,CAAC,CAAC;AACvC,SAAS;AACT,QAAQ,MAAM,KAAK,CAAC,CAAC,wBAAwB,EAAE,SAAS,CAAC,aAAa,CAAC,CAAC,CAAC;AACzE,KAAK;AACL,CAAC;AACM,SAAS,eAAe,CAAC,MAAM,EAAE;AACxC,IAAI,IAAI,kBAAkB,GAAG,IAAI,UAAU,CAAC,CAAC,MAAM,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC;AAC9D,IAAI,kBAAkB,GAAG,MAAM,CAAC,eAAe,CAAC,kBAAkB,CAAC,CAAC;AACpE,IAAI,MAAM,kBAAkB,GAAG,KAAK,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AAChG,IAAI,OAAO,kBAAkB,CAAC,SAAS,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;AACnD;;ACTA;AACO,MAAM,mBAAmB,SAASA,cAAS,CAAC;AACn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AAU,CAAC,WAAW,CAAC,IAAI,CAAC,oBAAoB,CAAC,aAAa,CAAC,CAAC,CAAC;AAC7E,SAAS,CAAC,CAAC;AACX,KAAK;AACL,IAAI,QAAQ,GAAG;AACf,QAAQ,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,4BAA4B,EAAE,MAAM,IAAI,CAAC,UAAU,CAAC,YAAY,CAAC,CAAC,CAAC;AACvG,QAAQ,OAAO,IAAI,CAAC,KAAK,CAAC;AAC1B,KAAK;AACL,IAAI,oBAAoB,CAAC,aAAa,EAAE;AACxC;AACA,QAAQ,MAAM,MAAM,GAAG,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;AACxD,QAAQ,MAAM,CAAC,YAAY,CAAC,OAAO,EAAE,wUAAwU,CAAC,CAAC;AAC/W,QAAQ,MAAM,CAAC,OAAO,GAAG,aAAa,CAAC;AACvC,QAAQ,MAAM,CAAC,SAAS,GAAG,CAAC;AAC5B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,YAAY,CAAC,CAAC;AACd,QAAQ,OAAO,MAAM,CAAC;AACtB,KAAK;AACL,CAAC;AACI,MAAC,gBAAgB,GAAG,IAAI,gBAAgB;;;;"}
1
+ {"version":3,"file":"plugin.cjs.js","sources":["esm/helpers.js","esm/web.js","esm/GoogleOneTapAuth.js"],"sourcesContent":["export function assert(predicate, customMessage) {\n if (!predicate()) {\n if (customMessage != undefined) {\n throw Error(customMessage);\n }\n throw Error(`Assert error, expected '${predicate}' to be true.`);\n }\n}\nexport function randomHexString(length) {\n let uint8RandomNumbers = new Uint8Array((length / 2) + 1);\n uint8RandomNumbers = crypto.getRandomValues(uint8RandomNumbers);\n const numbersAsHexString = Array.from(uint8RandomNumbers).map(x => x.toString(16)).join('');\n return numbersAsHexString.substring(0, length);\n}\n//# sourceMappingURL=helpers.js.map","import { WebPlugin } from '@capacitor/core';\nimport * as scriptjs from 'scriptjs';\nimport jwt_decode from 'jwt-decode';\nimport { assert } from './helpers';\n// See https://developers.google.com/identity/gsi/web/guides/use-one-tap-js-api\nexport class GoogleOneTapAuthWeb extends WebPlugin {\n constructor() {\n super(...arguments);\n this.gsiScriptUrl = 'https://accounts.google.com/gsi/client';\n this.gapiLoadedPromise = undefined;\n this.authenticatedUserId = undefined;\n this.clientId = undefined;\n this.nonce = undefined;\n }\n async initialize(options) {\n this.clientId = options.clientId;\n this.nonce = options.nonce;\n if (!this.gapiLoadedPromise) {\n this.gapiLoadedPromise = new Promise((resolve) => {\n scriptjs.get(this.gsiScriptUrl, () => {\n resolve();\n });\n });\n }\n return this.gapiLoadedPromise;\n }\n async tryAutoOrOneTapSignIn() {\n let signInResult = await this.doSignIn(true);\n if (!signInResult.idToken) {\n signInResult = await this.doSignIn(false);\n }\n if (signInResult.idToken) {\n return {\n isSuccess: true,\n success: signInResult\n };\n }\n else {\n return {\n isSuccess: false,\n noSuccess: signInResult\n };\n }\n }\n async renderSignInButton(parentElementId, options, gsiButtonConfiguration) {\n const parentElem = document.getElementById(parentElementId);\n assert(() => !!parentElem);\n var signInPromise = new Promise((resolve) => {\n this.oneTapInitialize(false, resolve, options.webOptions);\n google.accounts.id.renderButton(parentElem, gsiButtonConfiguration || {});\n });\n return signInPromise;\n }\n async doSignIn(autoSelect) {\n var signInPromise = new Promise((resolve) => {\n this.oneTapInitialize(autoSelect, resolve);\n google.accounts.id.prompt((notification) => {\n if (notification.isNotDisplayed()\n || notification.isSkippedMoment()\n || notification.isDismissedMoment()) {\n resolve({\n noSuccessReasonCode: this.getMomentReason(notification)\n });\n }\n });\n });\n return signInPromise;\n }\n getMomentReason(notification) {\n if (notification.isNotDisplayed()) {\n return notification.getNotDisplayedReason();\n }\n if (notification.isSkippedMoment()) {\n return notification.getSkippedReason();\n }\n if (notification.isDismissedMoment()) {\n return notification.getDismissedReason();\n }\n return undefined;\n }\n oneTapInitialize(autoSelect, resolveSignInFunc, webOptions) {\n google.accounts.id.initialize({\n client_id: this.clientId,\n callback: (credentialResponse) => this.handleCredentialResponse(credentialResponse, resolveSignInFunc),\n auto_select: autoSelect,\n itp_support: (webOptions === null || webOptions === void 0 ? void 0 : webOptions.itpSupport) || false,\n cancel_on_tap_outside: false,\n ux_mode: (webOptions === null || webOptions === void 0 ? void 0 : webOptions.uxMode) || 'popup',\n nonce: this.nonce,\n });\n }\n handleCredentialResponse(credentialResponse, resolveSignInFunc) {\n const decodedIdToken = jwt_decode(credentialResponse.credential);\n let signInResult = {\n idToken: credentialResponse.credential,\n userId: decodedIdToken.sub,\n email: decodedIdToken.email,\n selectBy: credentialResponse.select_by,\n decodedIdToken: decodedIdToken\n };\n this.authenticatedUserId = decodedIdToken['sub'];\n // console.log(decodedIdToken);\n resolveSignInFunc(signInResult);\n }\n signOut() {\n return new Promise((resolve) => {\n google.accounts.id.cancel();\n if (this.authenticatedUserId) {\n // Calling revoke method revokes all OAuth2 scopes previously granted by the Sign In With Google client library.\n google.accounts.id.revoke(this.authenticatedUserId, response => {\n if (response.successful) {\n resolve({ isSuccess: true });\n }\n else {\n resolve({ isSuccess: false, error: response.error });\n }\n });\n this.authenticatedUserId = undefined;\n }\n else {\n resolve({ isSuccess: true });\n }\n });\n }\n getNonce() {\n throw new Error('Should never be called because handled wrapper class.');\n }\n}\n//# sourceMappingURL=web.js.map","import { Capacitor, registerPlugin } from '@capacitor/core';\nimport { assert, randomHexString } from './helpers';\nimport { GoogleOneTapAuthWeb } from './web';\nconst GoogleOneTapAuthPlatform = registerPlugin('GoogleOneTapAuth', {\n web: () => new GoogleOneTapAuthWeb(),\n});\n// This file is the entry point for all plugin methods. It contains common logic to web, android, iOS or delegates to the specific implementation.\nclass GoogleOneTapAuth {\n constructor() {\n this.isInitialized = false;\n }\n async initialize(options) {\n if (!options.clientId || options.clientId.endsWith(\"apps.googleusercontent.com\") == false) {\n throw new Error(\"clientId must end with 'apps.googleusercontent.com' but is: \" + options.clientId);\n }\n this.nonce = options.nonce = options.nonce || randomHexString(10);\n await GoogleOneTapAuthPlatform.initialize(options);\n this.isInitialized = true;\n }\n async tryAutoOrOneTapSignIn() {\n assert(() => this.isInitialized, 'Must call and await initialize first.');\n const signInResultOptionPromise = GoogleOneTapAuthPlatform.tryAutoOrOneTapSignIn();\n let signInResultOption = await signInResultOptionPromise;\n if (signInResultOption.isSuccess) {\n return {\n successPromise: Promise.resolve(signInResultOption.success),\n noSuccess: new Promise(() => { }),\n signInResultOptionPromise: signInResultOptionPromise\n };\n }\n else {\n return {\n successPromise: new Promise(() => { }),\n noSuccess: Promise.resolve(signInResultOption.noSuccess),\n signInResultOptionPromise: signInResultOptionPromise\n };\n }\n }\n signOut() {\n return GoogleOneTapAuthPlatform.signOut();\n }\n renderSignInButton(parentElementId, options, gsiButtonConfiguration) {\n assert(() => this.isInitialized, 'Must call and await initialize first.');\n options.webOptions = options.webOptions || {};\n if (Capacitor.getPlatform() === 'web') {\n return GoogleOneTapAuthPlatform.renderSignInButton(parentElementId, options, gsiButtonConfiguration);\n }\n const parentElem = document.getElementById(parentElementId);\n assert(() => !!parentElem);\n return new Promise((resolve) => {\n const onClickAction = async () => {\n let signInResult = await GoogleOneTapAuthPlatform.triggerGoogleSignIn(options);\n if (Boolean(signInResult.idToken)) {\n resolve(signInResult);\n }\n };\n parentElem.appendChild(this._getSignInButtonHtml(onClickAction));\n });\n }\n getNonce() {\n assert(() => !!this.nonce, `The nonce is only set after ${() => this.initialize} was called.`);\n return this.nonce;\n }\n _getSignInButtonHtml(onClickAction) {\n // HTML from https://github.com/inouiw/ReactSignInWithGoogleButton\n const button = document.createElement('button');\n button.setAttribute(\"style\", \"border-radius: 4px; background-color: rgb(255, 255, 255); border: 1px solid rgb(218, 220, 224); color: rgb(60, 64, 67); cursor: pointer; font-family: Roboto; font-weight: 500; font-size: 14px; height: 40px; letter-spacing: 0.25px; padding: 0px 12px; position: relative; text-align: center; vertical-align: middle; width: auto;\");\n button.onclick = onClickAction;\n button.innerHTML = `\n <div style=\"display: flex; align-items: center; flex-flow: row nowrap; justify-content: space-between; height: 100%; position: relative; width: 100%;\">\n <div style=\"height: 18px; margin-right: 8px; min-width: 18px; width: 18px;\">\n <svg version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\" width=\"18px\" height=\"18px\" viewBox=\"0 0 48 48\">\n <g>\n <path fill=\"#EA4335\" d=\"M24 9.5c3.54 0 6.71 1.22 9.21 3.6l6.85-6.85C35.9 2.38 30.47 0 24 0 14.62 0 6.51 5.38 2.56 13.22l7.98 6.19C12.43 13.72 17.74 9.5 24 9.5z\"></path>\n <path fill=\"#4285F4\" d=\"M46.98 24.55c0-1.57-.15-3.09-.38-4.55H24v9.02h12.94c-.58 2.96-2.26 5.48-4.78 7.18l7.73 6c4.51-4.18 7.09-10.36 7.09-17.65z\"></path>\n <path fill=\"#FBBC05\" d=\"M10.53 28.59c-.48-1.45-.76-2.99-.76-4.59s.27-3.14.76-4.59l-7.98-6.19C.92 16.46 0 20.12 0 24c0 3.88.92 7.54 2.56 10.78l7.97-6.19z\"></path>\n <path fill=\"#34A853\" d=\"M24 48c6.48 0 11.93-2.13 15.89-5.81l-7.73-6c-2.15 1.45-4.92 2.3-8.16 2.3-6.26 0-11.57-4.22-13.47-9.91l-7.98 6.19C6.51 42.62 14.62 48 24 48z\"></path>\n <path fill=\"none\" d=\"M0 0h48v48H0z\"></path>\n </g>\n </svg>\n </div>\n <p>Sign in with Google</p>\n </div>`;\n return button;\n }\n}\nconst googleOneTapAuth = new GoogleOneTapAuth();\nexport { googleOneTapAuth as GoogleOneTapAuth };\n//# sourceMappingURL=GoogleOneTapAuth.js.map"],"names":["WebPlugin","scriptjs","jwt_decode","registerPlugin","Capacitor"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAO,SAAS,MAAM,CAAC,SAAS,EAAE,aAAa,EAAE;AACjD,IAAI,IAAI,CAAC,SAAS,EAAE,EAAE;AACtB,QAAQ,IAAI,aAAa,IAAI,SAAS,EAAE;A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AAC,YAAY,CAAC,OAAO,EAAE,wUAAwU,CAAC,CAAC;AAC/W,QAAQ,MAAM,CAAC,OAAO,GAAG,aAAa,CAAC;AACvC,QAAQ,MAAM,CAAC,SAAS,GAAG,CAAC;AAC5B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,YAAY,CAAC,CAAC;AACd,QAAQ,OAAO,MAAM,CAAC;AACtB,KAAK;AACL,CAAC;AACI,MAAC,gBAAgB,GAAG,IAAI,gBAAgB;;;;"}
package/dist/plugin.js CHANGED
@@ -212,8 +212,10 @@ var capacitorNativeGoogleOneTapSignin = (function (exports, core, scriptjs, jwt_
212
212
  assert(() => !!parentElem);
213
213
  return new Promise((resolve) => {
214
214
  const onClickAction = async () => {
215
- const signInResult = await GoogleOneTapAuthPlatform.triggerGoogleSignIn(options);
216
- resolve(signInResult);
215
+ let signInResult = await GoogleOneTapAuthPlatform.triggerGoogleSignIn(options);
216
+ if (Boolean(signInResult.idToken)) {
217
+ resolve(signInResult);
218
+ }
217
219
  };
218
220
  parentElem.appendChild(this._getSignInButtonHtml(onClickAction));
219
221
  });
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.js","sources":["esm/helpers.js","esm/web.js","esm/GoogleOneTapAuth.js"],"sourcesContent":["export function assert(predicate, customMessage) {\n if (!predicate()) {\n if (customMessage != undefined) {\n throw Error(customMessage);\n }\n throw Error(`Assert error, expected '${predicate}' to be true.`);\n }\n}\nexport function randomHexString(length) {\n let uint8RandomNumbers = new Uint8Array((length / 2) + 1);\n uint8RandomNumbers = crypto.getRandomValues(uint8RandomNumbers);\n const numbersAsHexString = Array.from(uint8RandomNumbers).map(x => x.toString(16)).join('');\n return numbersAsHexString.substring(0, length);\n}\n//# sourceMappingURL=helpers.js.map","import { WebPlugin } from '@capacitor/core';\nimport * as scriptjs from 'scriptjs';\nimport jwt_decode from 'jwt-decode';\nimport { assert } from './helpers';\n// See https://developers.google.com/identity/gsi/web/guides/use-one-tap-js-api\nexport class GoogleOneTapAuthWeb extends WebPlugin {\n constructor() {\n super(...arguments);\n this.gsiScriptUrl = 'https://accounts.google.com/gsi/client';\n this.gapiLoadedPromise = undefined;\n this.authenticatedUserId = undefined;\n this.clientId = undefined;\n this.nonce = undefined;\n }\n async initialize(options) {\n this.clientId = options.clientId;\n this.nonce = options.nonce;\n if (!this.gapiLoadedPromise) {\n this.gapiLoadedPromise = new Promise((resolve) => {\n scriptjs.get(this.gsiScriptUrl, () => {\n resolve();\n });\n });\n }\n return this.gapiLoadedPromise;\n }\n async tryAutoOrOneTapSignIn() {\n let signInResult = await this.doSignIn(true);\n if (!signInResult.idToken) {\n signInResult = await this.doSignIn(false);\n }\n if (signInResult.idToken) {\n return {\n isSuccess: true,\n success: signInResult\n };\n }\n else {\n return {\n isSuccess: false,\n noSuccess: signInResult\n };\n }\n }\n async renderSignInButton(parentElementId, options, gsiButtonConfiguration) {\n const parentElem = document.getElementById(parentElementId);\n assert(() => !!parentElem);\n var signInPromise = new Promise((resolve) => {\n this.oneTapInitialize(false, resolve, options.webOptions);\n google.accounts.id.renderButton(parentElem, gsiButtonConfiguration || {});\n });\n return signInPromise;\n }\n async doSignIn(autoSelect) {\n var signInPromise = new Promise((resolve) => {\n this.oneTapInitialize(autoSelect, resolve);\n google.accounts.id.prompt((notification) => {\n if (notification.isNotDisplayed()\n || notification.isSkippedMoment()\n || notification.isDismissedMoment()) {\n resolve({\n noSuccessReasonCode: this.getMomentReason(notification)\n });\n }\n });\n });\n return signInPromise;\n }\n getMomentReason(notification) {\n if (notification.isNotDisplayed()) {\n return notification.getNotDisplayedReason();\n }\n if (notification.isSkippedMoment()) {\n return notification.getSkippedReason();\n }\n if (notification.isDismissedMoment()) {\n return notification.getDismissedReason();\n }\n return undefined;\n }\n oneTapInitialize(autoSelect, resolveSignInFunc, webOptions) {\n google.accounts.id.initialize({\n client_id: this.clientId,\n callback: (credentialResponse) => this.handleCredentialResponse(credentialResponse, resolveSignInFunc),\n auto_select: autoSelect,\n itp_support: (webOptions === null || webOptions === void 0 ? void 0 : webOptions.itpSupport) || false,\n cancel_on_tap_outside: false,\n ux_mode: (webOptions === null || webOptions === void 0 ? void 0 : webOptions.uxMode) || 'popup',\n nonce: this.nonce,\n });\n }\n handleCredentialResponse(credentialResponse, resolveSignInFunc) {\n const decodedIdToken = jwt_decode(credentialResponse.credential);\n let signInResult = {\n idToken: credentialResponse.credential,\n userId: decodedIdToken.sub,\n email: decodedIdToken.email,\n selectBy: credentialResponse.select_by,\n decodedIdToken: decodedIdToken\n };\n this.authenticatedUserId = decodedIdToken['sub'];\n // console.log(decodedIdToken);\n resolveSignInFunc(signInResult);\n }\n signOut() {\n return new Promise((resolve) => {\n google.accounts.id.cancel();\n if (this.authenticatedUserId) {\n // Calling revoke method revokes all OAuth2 scopes previously granted by the Sign In With Google client library.\n google.accounts.id.revoke(this.authenticatedUserId, response => {\n if (response.successful) {\n resolve({ isSuccess: true });\n }\n else {\n resolve({ isSuccess: false, error: response.error });\n }\n });\n this.authenticatedUserId = undefined;\n }\n else {\n resolve({ isSuccess: true });\n }\n });\n }\n getNonce() {\n throw new Error('Should never be called because handled wrapper class.');\n }\n}\n//# sourceMappingURL=web.js.map","import { Capacitor, registerPlugin } from '@capacitor/core';\nimport { assert, randomHexString } from './helpers';\nimport { GoogleOneTapAuthWeb } from './web';\nconst GoogleOneTapAuthPlatform = registerPlugin('GoogleOneTapAuth', {\n web: () => new GoogleOneTapAuthWeb(),\n});\n// This file is the entry point for all plugin methods. It contains common logic to web, android, iOS or delegates to the specific implementation.\nclass GoogleOneTapAuth {\n constructor() {\n this.isInitialized = false;\n }\n async initialize(options) {\n if (!options.clientId || options.clientId.endsWith(\"apps.googleusercontent.com\") == false) {\n throw new Error(\"clientId must end with 'apps.googleusercontent.com' but is: \" + options.clientId);\n }\n this.nonce = options.nonce = options.nonce || randomHexString(10);\n await GoogleOneTapAuthPlatform.initialize(options);\n this.isInitialized = true;\n }\n async tryAutoOrOneTapSignIn() {\n assert(() => this.isInitialized, 'Must call and await initialize first.');\n const signInResultOptionPromise = GoogleOneTapAuthPlatform.tryAutoOrOneTapSignIn();\n let signInResultOption = await signInResultOptionPromise;\n if (signInResultOption.isSuccess) {\n return {\n successPromise: Promise.resolve(signInResultOption.success),\n noSuccess: new Promise(() => { }),\n signInResultOptionPromise: signInResultOptionPromise\n };\n }\n else {\n return {\n successPromise: new Promise(() => { }),\n noSuccess: Promise.resolve(signInResultOption.noSuccess),\n signInResultOptionPromise: signInResultOptionPromise\n };\n }\n }\n signOut() {\n return GoogleOneTapAuthPlatform.signOut();\n }\n renderSignInButton(parentElementId, options, gsiButtonConfiguration) {\n assert(() => this.isInitialized, 'Must call and await initialize first.');\n options.webOptions = options.webOptions || {};\n if (Capacitor.getPlatform() === 'web') {\n return GoogleOneTapAuthPlatform.renderSignInButton(parentElementId, options, gsiButtonConfiguration);\n }\n const parentElem = document.getElementById(parentElementId);\n assert(() => !!parentElem);\n return new Promise((resolve) => {\n const onClickAction = async () => {\n const signInResult = await GoogleOneTapAuthPlatform.triggerGoogleSignIn(options);\n resolve(signInResult);\n };\n parentElem.appendChild(this._getSignInButtonHtml(onClickAction));\n });\n }\n getNonce() {\n assert(() => !!this.nonce, `The nonce is only set after ${() => this.initialize} was called.`);\n return this.nonce;\n }\n _getSignInButtonHtml(onClickAction) {\n // HTML from https://github.com/inouiw/ReactSignInWithGoogleButton\n const button = document.createElement('button');\n button.setAttribute(\"style\", \"border-radius: 4px; background-color: rgb(255, 255, 255); border: 1px solid rgb(218, 220, 224); color: rgb(60, 64, 67); cursor: pointer; font-family: Roboto; font-weight: 500; font-size: 14px; height: 40px; letter-spacing: 0.25px; padding: 0px 12px; position: relative; text-align: center; vertical-align: middle; width: auto;\");\n button.onclick = onClickAction;\n button.innerHTML = `\n <div style=\"display: flex; align-items: center; flex-flow: row nowrap; justify-content: space-between; height: 100%; position: relative; width: 100%;\">\n <div style=\"height: 18px; margin-right: 8px; min-width: 18px; width: 18px;\">\n <svg version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\" width=\"18px\" height=\"18px\" viewBox=\"0 0 48 48\">\n <g>\n <path fill=\"#EA4335\" d=\"M24 9.5c3.54 0 6.71 1.22 9.21 3.6l6.85-6.85C35.9 2.38 30.47 0 24 0 14.62 0 6.51 5.38 2.56 13.22l7.98 6.19C12.43 13.72 17.74 9.5 24 9.5z\"></path>\n <path fill=\"#4285F4\" d=\"M46.98 24.55c0-1.57-.15-3.09-.38-4.55H24v9.02h12.94c-.58 2.96-2.26 5.48-4.78 7.18l7.73 6c4.51-4.18 7.09-10.36 7.09-17.65z\"></path>\n <path fill=\"#FBBC05\" d=\"M10.53 28.59c-.48-1.45-.76-2.99-.76-4.59s.27-3.14.76-4.59l-7.98-6.19C.92 16.46 0 20.12 0 24c0 3.88.92 7.54 2.56 10.78l7.97-6.19z\"></path>\n <path fill=\"#34A853\" d=\"M24 48c6.48 0 11.93-2.13 15.89-5.81l-7.73-6c-2.15 1.45-4.92 2.3-8.16 2.3-6.26 0-11.57-4.22-13.47-9.91l-7.98 6.19C6.51 42.62 14.62 48 24 48z\"></path>\n <path fill=\"none\" d=\"M0 0h48v48H0z\"></path>\n </g>\n </svg>\n </div>\n <p>Sign in with Google</p>\n </div>`;\n return button;\n }\n}\nconst googleOneTapAuth = new GoogleOneTapAuth();\nexport { googleOneTapAuth as GoogleOneTapAuth };\n//# sourceMappingURL=GoogleOneTapAuth.js.map"],"names":["WebPlugin","scriptjs","jwt_decode","registerPlugin","Capacitor"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;IAAO,SAAS,MAAM,CAAC,SAAS,EAAE,aAAa,EAAE;IACjD,IAAI,IAAI,CAAC,SAAS,EAAE,EAAE;IACtB,QAAQ,IAAI,aAAa,IAAI,SAAS,EAAE;IACxC,YAAY,MAAM,KAAK,CAAC,aAAa,CAAC,CAAC;IACvC,SAAS;IACT,QAAQ,MAAM,KAAK,CAAC,CAAC,wBAAwB,EAAE,SAAS,CAA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AACA;AACA;AACA,YAAY,CAAC,CAAC;IACd,QAAQ,OAAO,MAAM,CAAC;IACtB,KAAK;IACL,CAAC;AACI,UAAC,gBAAgB,GAAG,IAAI,gBAAgB;;;;;;;;;;;;"}
1
+ {"version":3,"file":"plugin.js","sources":["esm/helpers.js","esm/web.js","esm/GoogleOneTapAuth.js"],"sourcesContent":["export function assert(predicate, customMessage) {\n if (!predicate()) {\n if (customMessage != undefined) {\n throw Error(customMessage);\n }\n throw Error(`Assert error, expected '${predicate}' to be true.`);\n }\n}\nexport function randomHexString(length) {\n let uint8RandomNumbers = new Uint8Array((length / 2) + 1);\n uint8RandomNumbers = crypto.getRandomValues(uint8RandomNumbers);\n const numbersAsHexString = Array.from(uint8RandomNumbers).map(x => x.toString(16)).join('');\n return numbersAsHexString.substring(0, length);\n}\n//# sourceMappingURL=helpers.js.map","import { WebPlugin } from '@capacitor/core';\nimport * as scriptjs from 'scriptjs';\nimport jwt_decode from 'jwt-decode';\nimport { assert } from './helpers';\n// See https://developers.google.com/identity/gsi/web/guides/use-one-tap-js-api\nexport class GoogleOneTapAuthWeb extends WebPlugin {\n constructor() {\n super(...arguments);\n this.gsiScriptUrl = 'https://accounts.google.com/gsi/client';\n this.gapiLoadedPromise = undefined;\n this.authenticatedUserId = undefined;\n this.clientId = undefined;\n this.nonce = undefined;\n }\n async initialize(options) {\n this.clientId = options.clientId;\n this.nonce = options.nonce;\n if (!this.gapiLoadedPromise) {\n this.gapiLoadedPromise = new Promise((resolve) => {\n scriptjs.get(this.gsiScriptUrl, () => {\n resolve();\n });\n });\n }\n return this.gapiLoadedPromise;\n }\n async tryAutoOrOneTapSignIn() {\n let signInResult = await this.doSignIn(true);\n if (!signInResult.idToken) {\n signInResult = await this.doSignIn(false);\n }\n if (signInResult.idToken) {\n return {\n isSuccess: true,\n success: signInResult\n };\n }\n else {\n return {\n isSuccess: false,\n noSuccess: signInResult\n };\n }\n }\n async renderSignInButton(parentElementId, options, gsiButtonConfiguration) {\n const parentElem = document.getElementById(parentElementId);\n assert(() => !!parentElem);\n var signInPromise = new Promise((resolve) => {\n this.oneTapInitialize(false, resolve, options.webOptions);\n google.accounts.id.renderButton(parentElem, gsiButtonConfiguration || {});\n });\n return signInPromise;\n }\n async doSignIn(autoSelect) {\n var signInPromise = new Promise((resolve) => {\n this.oneTapInitialize(autoSelect, resolve);\n google.accounts.id.prompt((notification) => {\n if (notification.isNotDisplayed()\n || notification.isSkippedMoment()\n || notification.isDismissedMoment()) {\n resolve({\n noSuccessReasonCode: this.getMomentReason(notification)\n });\n }\n });\n });\n return signInPromise;\n }\n getMomentReason(notification) {\n if (notification.isNotDisplayed()) {\n return notification.getNotDisplayedReason();\n }\n if (notification.isSkippedMoment()) {\n return notification.getSkippedReason();\n }\n if (notification.isDismissedMoment()) {\n return notification.getDismissedReason();\n }\n return undefined;\n }\n oneTapInitialize(autoSelect, resolveSignInFunc, webOptions) {\n google.accounts.id.initialize({\n client_id: this.clientId,\n callback: (credentialResponse) => this.handleCredentialResponse(credentialResponse, resolveSignInFunc),\n auto_select: autoSelect,\n itp_support: (webOptions === null || webOptions === void 0 ? void 0 : webOptions.itpSupport) || false,\n cancel_on_tap_outside: false,\n ux_mode: (webOptions === null || webOptions === void 0 ? void 0 : webOptions.uxMode) || 'popup',\n nonce: this.nonce,\n });\n }\n handleCredentialResponse(credentialResponse, resolveSignInFunc) {\n const decodedIdToken = jwt_decode(credentialResponse.credential);\n let signInResult = {\n idToken: credentialResponse.credential,\n userId: decodedIdToken.sub,\n email: decodedIdToken.email,\n selectBy: credentialResponse.select_by,\n decodedIdToken: decodedIdToken\n };\n this.authenticatedUserId = decodedIdToken['sub'];\n // console.log(decodedIdToken);\n resolveSignInFunc(signInResult);\n }\n signOut() {\n return new Promise((resolve) => {\n google.accounts.id.cancel();\n if (this.authenticatedUserId) {\n // Calling revoke method revokes all OAuth2 scopes previously granted by the Sign In With Google client library.\n google.accounts.id.revoke(this.authenticatedUserId, response => {\n if (response.successful) {\n resolve({ isSuccess: true });\n }\n else {\n resolve({ isSuccess: false, error: response.error });\n }\n });\n this.authenticatedUserId = undefined;\n }\n else {\n resolve({ isSuccess: true });\n }\n });\n }\n getNonce() {\n throw new Error('Should never be called because handled wrapper class.');\n }\n}\n//# sourceMappingURL=web.js.map","import { Capacitor, registerPlugin } from '@capacitor/core';\nimport { assert, randomHexString } from './helpers';\nimport { GoogleOneTapAuthWeb } from './web';\nconst GoogleOneTapAuthPlatform = registerPlugin('GoogleOneTapAuth', {\n web: () => new GoogleOneTapAuthWeb(),\n});\n// This file is the entry point for all plugin methods. It contains common logic to web, android, iOS or delegates to the specific implementation.\nclass GoogleOneTapAuth {\n constructor() {\n this.isInitialized = false;\n }\n async initialize(options) {\n if (!options.clientId || options.clientId.endsWith(\"apps.googleusercontent.com\") == false) {\n throw new Error(\"clientId must end with 'apps.googleusercontent.com' but is: \" + options.clientId);\n }\n this.nonce = options.nonce = options.nonce || randomHexString(10);\n await GoogleOneTapAuthPlatform.initialize(options);\n this.isInitialized = true;\n }\n async tryAutoOrOneTapSignIn() {\n assert(() => this.isInitialized, 'Must call and await initialize first.');\n const signInResultOptionPromise = GoogleOneTapAuthPlatform.tryAutoOrOneTapSignIn();\n let signInResultOption = await signInResultOptionPromise;\n if (signInResultOption.isSuccess) {\n return {\n successPromise: Promise.resolve(signInResultOption.success),\n noSuccess: new Promise(() => { }),\n signInResultOptionPromise: signInResultOptionPromise\n };\n }\n else {\n return {\n successPromise: new Promise(() => { }),\n noSuccess: Promise.resolve(signInResultOption.noSuccess),\n signInResultOptionPromise: signInResultOptionPromise\n };\n }\n }\n signOut() {\n return GoogleOneTapAuthPlatform.signOut();\n }\n renderSignInButton(parentElementId, options, gsiButtonConfiguration) {\n assert(() => this.isInitialized, 'Must call and await initialize first.');\n options.webOptions = options.webOptions || {};\n if (Capacitor.getPlatform() === 'web') {\n return GoogleOneTapAuthPlatform.renderSignInButton(parentElementId, options, gsiButtonConfiguration);\n }\n const parentElem = document.getElementById(parentElementId);\n assert(() => !!parentElem);\n return new Promise((resolve) => {\n const onClickAction = async () => {\n let signInResult = await GoogleOneTapAuthPlatform.triggerGoogleSignIn(options);\n if (Boolean(signInResult.idToken)) {\n resolve(signInResult);\n }\n };\n parentElem.appendChild(this._getSignInButtonHtml(onClickAction));\n });\n }\n getNonce() {\n assert(() => !!this.nonce, `The nonce is only set after ${() => this.initialize} was called.`);\n return this.nonce;\n }\n _getSignInButtonHtml(onClickAction) {\n // HTML from https://github.com/inouiw/ReactSignInWithGoogleButton\n const button = document.createElement('button');\n button.setAttribute(\"style\", \"border-radius: 4px; background-color: rgb(255, 255, 255); border: 1px solid rgb(218, 220, 224); color: rgb(60, 64, 67); cursor: pointer; font-family: Roboto; font-weight: 500; font-size: 14px; height: 40px; letter-spacing: 0.25px; padding: 0px 12px; position: relative; text-align: center; vertical-align: middle; width: auto;\");\n button.onclick = onClickAction;\n button.innerHTML = `\n <div style=\"display: flex; align-items: center; flex-flow: row nowrap; justify-content: space-between; height: 100%; position: relative; width: 100%;\">\n <div style=\"height: 18px; margin-right: 8px; min-width: 18px; width: 18px;\">\n <svg version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\" width=\"18px\" height=\"18px\" viewBox=\"0 0 48 48\">\n <g>\n <path fill=\"#EA4335\" d=\"M24 9.5c3.54 0 6.71 1.22 9.21 3.6l6.85-6.85C35.9 2.38 30.47 0 24 0 14.62 0 6.51 5.38 2.56 13.22l7.98 6.19C12.43 13.72 17.74 9.5 24 9.5z\"></path>\n <path fill=\"#4285F4\" d=\"M46.98 24.55c0-1.57-.15-3.09-.38-4.55H24v9.02h12.94c-.58 2.96-2.26 5.48-4.78 7.18l7.73 6c4.51-4.18 7.09-10.36 7.09-17.65z\"></path>\n <path fill=\"#FBBC05\" d=\"M10.53 28.59c-.48-1.45-.76-2.99-.76-4.59s.27-3.14.76-4.59l-7.98-6.19C.92 16.46 0 20.12 0 24c0 3.88.92 7.54 2.56 10.78l7.97-6.19z\"></path>\n <path fill=\"#34A853\" d=\"M24 48c6.48 0 11.93-2.13 15.89-5.81l-7.73-6c-2.15 1.45-4.92 2.3-8.16 2.3-6.26 0-11.57-4.22-13.47-9.91l-7.98 6.19C6.51 42.62 14.62 48 24 48z\"></path>\n <path fill=\"none\" d=\"M0 0h48v48H0z\"></path>\n </g>\n </svg>\n </div>\n <p>Sign in with Google</p>\n </div>`;\n return button;\n }\n}\nconst googleOneTapAuth = new GoogleOneTapAuth();\nexport { googleOneTapAuth as GoogleOneTapAuth };\n//# sourceMappingURL=GoogleOneTapAuth.js.map"],"names":["WebPlugin","scriptjs","jwt_decode","registerPlugin","Capacitor"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;IAAO,SAAS,MAAM,CAAC,SAAS,EAAE,aAAa,EAAE;IACjD,IAAI,IAAI,CAAC,SAAS,EAAE,EAAE;IACtB,QAAQ,IAAI,aAAa,IAAI,SAAS,EAAE;IACxC,YAAY,MAAM,KAAK,CAAC,aAAa,CAAC,CAAC;IACvC,SAAS;IACT,QAAQ,MAAM,KAAK,CAAC,CAAC,wBAAwB,EAAE,SAAS,CAAC,aAAa,CAAC,CAAC,CAAC;IACzE,KAAK;IACL,CAAC;IACM,SAAS,eAAe,CAAC,MAAM,EAAE;IACxC,IAAI,IAAI,kBAAkB,GAAG,IAAI,UAAU,CAAC,CAAC,MAAM,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC;IAC9D,IAAI,kBAAkB,GAAG,MAAM,CAAC,eAAe,CAAC,kBAAkB,CAAC,CAAC;IACpE,IAAI,MAAM,kBAAkB,GAAG,KAAK,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAChG,IAAI,OAAO,kBAAkB,CAAC,SAAS,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;IACnD;;ICTA;IACO,MAAM,mBAAmB,SAASA,c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AE;IACnD,oBAAoB,OAAO,CAAC,YAAY,CAAC,CAAC;IAC1C,iBAAiB;IACjB,aAAa,CAAC;IACd,YAAY,UAAU,CAAC,WAAW,CAAC,IAAI,CAAC,oBAAoB,CAAC,aAAa,CAAC,CAAC,CAAC;IAC7E,SAAS,CAAC,CAAC;IACX,KAAK;IACL,IAAI,QAAQ,GAAG;IACf,QAAQ,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,4BAA4B,EAAE,MAAM,IAAI,CAAC,UAAU,CAAC,YAAY,CAAC,CAAC,CAAC;IACvG,QAAQ,OAAO,IAAI,CAAC,KAAK,CAAC;IAC1B,KAAK;IACL,IAAI,oBAAoB,CAAC,aAAa,EAAE;IACxC;IACA,QAAQ,MAAM,MAAM,GAAG,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;IACxD,QAAQ,MAAM,CAAC,YAAY,CAAC,OAAO,EAAE,wUAAwU,CAAC,CAAC;IAC/W,QAAQ,MAAM,CAAC,OAAO,GAAG,aAAa,CAAC;IACvC,QAAQ,MAAM,CAAC,SAAS,GAAG,CAAC;AAC5B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,YAAY,CAAC,CAAC;IACd,QAAQ,OAAO,MAAM,CAAC;IACtB,KAAK;IACL,CAAC;AACI,UAAC,gBAAgB,GAAG,IAAI,gBAAgB;;;;;;;;;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "capacitor-native-google-one-tap-signin",
3
- "version": "0.5.0",
3
+ "version": "0.5.2",
4
4
  "description": "Google One Tap sign-in plugin for capacitor.",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",
@@ -48,6 +48,7 @@
48
48
  "swiftlint": "node-swiftlint",
49
49
  "docgen": "docgen --api GoogleOneTapAuthPlugin --output-readme README.md --output-json dist/docs.json",
50
50
  "build": "npm run clean && npm run docgen && tsc && rollup -c rollup.config.js",
51
+ "buildall": "npm run clean && npm run docgen && tsc && rollup -c rollup.config.js && (cd ./demo/react && npm run build && npx cap sync --inline && cd -)",
51
52
  "clean": "rimraf ./dist",
52
53
  "watch": "tsc --watch",
53
54
  "prepublishOnly": "npm run build"