@capawesome/capacitor-google-sign-in 0.0.1

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.
Files changed (39) hide show
  1. package/CapawesomeCapacitorGoogleSignIn.podspec +19 -0
  2. package/Package.swift +30 -0
  3. package/README.md +276 -0
  4. package/android/build.gradle +65 -0
  5. package/android/src/main/AndroidManifest.xml +2 -0
  6. package/android/src/main/java/io/capawesome/capacitorjs/plugins/googlesignin/GoogleSignIn.java +300 -0
  7. package/android/src/main/java/io/capawesome/capacitorjs/plugins/googlesignin/GoogleSignInPlugin.java +159 -0
  8. package/android/src/main/java/io/capawesome/capacitorjs/plugins/googlesignin/classes/CustomException.java +20 -0
  9. package/android/src/main/java/io/capawesome/capacitorjs/plugins/googlesignin/classes/CustomExceptions.java +11 -0
  10. package/android/src/main/java/io/capawesome/capacitorjs/plugins/googlesignin/classes/options/InitializeOptions.java +56 -0
  11. package/android/src/main/java/io/capawesome/capacitorjs/plugins/googlesignin/classes/options/SignInOptions.java +25 -0
  12. package/android/src/main/java/io/capawesome/capacitorjs/plugins/googlesignin/classes/results/SignInResult.java +75 -0
  13. package/android/src/main/java/io/capawesome/capacitorjs/plugins/googlesignin/interfaces/Callback.java +5 -0
  14. package/android/src/main/java/io/capawesome/capacitorjs/plugins/googlesignin/interfaces/EmptyCallback.java +5 -0
  15. package/android/src/main/java/io/capawesome/capacitorjs/plugins/googlesignin/interfaces/NonEmptyResultCallback.java +7 -0
  16. package/android/src/main/java/io/capawesome/capacitorjs/plugins/googlesignin/interfaces/Result.java +7 -0
  17. package/android/src/main/res/.gitkeep +0 -0
  18. package/dist/docs.json +310 -0
  19. package/dist/esm/definitions.d.ts +173 -0
  20. package/dist/esm/definitions.js +13 -0
  21. package/dist/esm/definitions.js.map +1 -0
  22. package/dist/esm/index.d.ts +4 -0
  23. package/dist/esm/index.js +7 -0
  24. package/dist/esm/index.js.map +1 -0
  25. package/dist/esm/web.d.ts +13 -0
  26. package/dist/esm/web.js +106 -0
  27. package/dist/esm/web.js.map +1 -0
  28. package/dist/plugin.cjs.js +133 -0
  29. package/dist/plugin.cjs.js.map +1 -0
  30. package/dist/plugin.js +136 -0
  31. package/dist/plugin.js.map +1 -0
  32. package/ios/Plugin/Classes/Options/InitializeOptions.swift +19 -0
  33. package/ios/Plugin/Classes/Results/SignInResult.swift +50 -0
  34. package/ios/Plugin/Enums/CustomError.swift +38 -0
  35. package/ios/Plugin/GoogleSignIn.swift +90 -0
  36. package/ios/Plugin/GoogleSignInPlugin.swift +81 -0
  37. package/ios/Plugin/Info.plist +24 -0
  38. package/ios/Plugin/Protocols/Result.swift +5 -0
  39. package/package.json +93 -0
@@ -0,0 +1,19 @@
1
+ require 'json'
2
+
3
+ package = JSON.parse(File.read(File.join(__dir__, 'package.json')))
4
+
5
+ Pod::Spec.new do |s|
6
+ s.name = 'CapawesomeCapacitorGoogleSignIn'
7
+ s.version = package['version']
8
+ s.summary = package['description']
9
+ s.license = package['license']
10
+ s.homepage = package['repository']['url']
11
+ s.author = package['author']
12
+ s.source = { :git => package['repository']['url'], :tag => s.version.to_s }
13
+ s.source_files = 'ios/Plugin/**/*.{swift,h,m,c,cc,mm,cpp}'
14
+ s.ios.deployment_target = '15.0'
15
+ s.dependency 'Capacitor'
16
+ s.dependency 'GoogleSignIn', '~> 8.0'
17
+ s.static_framework = true
18
+ s.swift_version = '5.1'
19
+ end
package/Package.swift ADDED
@@ -0,0 +1,30 @@
1
+ // swift-tools-version: 5.9
2
+ import PackageDescription
3
+
4
+ let package = Package(
5
+ name: "CapawesomeCapacitorGoogleSignIn",
6
+ platforms: [.iOS(.v15)],
7
+ products: [
8
+ .library(
9
+ name: "CapawesomeCapacitorGoogleSignIn",
10
+ targets: ["GoogleSignInPlugin"])
11
+ ],
12
+ dependencies: [
13
+ .package(url: "https://github.com/ionic-team/capacitor-swift-pm.git", from: "8.0.0"),
14
+ .package(url: "https://github.com/google/GoogleSignIn-iOS", .upToNextMajor(from: "8.0.0"))
15
+ ],
16
+ targets: [
17
+ .target(
18
+ name: "GoogleSignInPlugin",
19
+ dependencies: [
20
+ .product(name: "Capacitor", package: "capacitor-swift-pm"),
21
+ .product(name: "Cordova", package: "capacitor-swift-pm"),
22
+ .product(name: "GoogleSignIn", package: "GoogleSignIn-iOS")
23
+ ],
24
+ path: "ios/Plugin"),
25
+ .testTarget(
26
+ name: "GoogleSignInPluginTests",
27
+ dependencies: ["GoogleSignInPlugin"],
28
+ path: "ios/PluginTests")
29
+ ]
30
+ )
package/README.md ADDED
@@ -0,0 +1,276 @@
1
+ # @capawesome/capacitor-google-sign-in
2
+
3
+ Unofficial Capacitor plugin to sign-in with Google.[^1]
4
+
5
+ <div class="capawesome-z29o10a">
6
+ <a href="https://cloud.capawesome.io/" target="_blank">
7
+ <img alt="Deliver Live Updates to your Capacitor app with Capawesome Cloud" src="https://cloud.capawesome.io/assets/banners/cloud-build-and-deploy-capacitor-apps.png?t=1" />
8
+ </a>
9
+ </div>
10
+
11
+ ## Features
12
+
13
+ We are proud to offer a comprehensive Capacitor plugin for Google Sign-In. Here are some of the key features:
14
+
15
+ - đŸ–Ĩī¸ **Cross-platform**: Supports Android, iOS, and Web.
16
+ - 🔐 **Authentication**: Sign in users with their Google account and receive an ID token (JWT).
17
+ - 🔑 **Authorization**: Optionally request OAuth scopes to get an access token and server auth code.
18
+ - 👤 **User Profile**: Retrieve the user's email, display name, profile picture, and more.
19
+ - đŸ›Ąī¸ **Nonce Support**: Prevent replay attacks with a custom nonce on Android and Web.
20
+ - đŸĒļ **Lightweight**: Just a single dependency and zero unnecessary bloat.
21
+ - 🚨 **Error Codes**: Provides detailed error codes for better error handling.
22
+ - 🤝 **Compatibility**: Compatible with the [OAuth](https://capawesome.io/plugins/oauth) plugins.
23
+ - đŸ“Ļ **CocoaPods & SPM**: Supports CocoaPods and Swift Package Manager for iOS.
24
+ - 🔁 **Up-to-date**: Always supports the latest Capacitor version.
25
+
26
+ Missing a feature? Just [open an issue](https://github.com/capawesome-team/capacitor-plugins/issues) and we'll take a look!
27
+
28
+ ## Compatibility
29
+
30
+ | Plugin Version | Capacitor Version | Status |
31
+ | -------------- | ----------------- | -------------- |
32
+ | 0.1.x | >=8.x.x | Active support |
33
+
34
+ ## Guides
35
+
36
+ - [How to Sign In with Google using Capacitor](https://capawesome.io/blog/how-to-sign-in-with-google-using-capacitor/)
37
+
38
+ ## Installation
39
+
40
+ ```bash
41
+ npm install @capawesome/capacitor-google-sign-in
42
+ npx cap sync
43
+ ```
44
+
45
+ ### Android
46
+
47
+ #### Variables
48
+
49
+ This plugin will use the following project variables (defined in your app's `variables.gradle` file):
50
+
51
+ - `$androidxCredentialsVersion` version of `androidx.credentials:credentials` (default: `1.5.0`)
52
+ - `$googleIdVersion` version of `com.google.android.libraries.identity.googleid:googleid` (default: `1.1.1`)
53
+ - `$playServicesAuthVersion` version of `com.google.android.gms:play-services-auth` (default: `21.5.0`)
54
+
55
+ ### iOS
56
+
57
+ Add the `GIDClientID` key to the `ios/App/App/Info.plist` file with your iOS client ID from the Google Cloud Console:
58
+
59
+ ```xml
60
+ <key>GIDClientID</key>
61
+ <string>YOUR_IOS_CLIENT_ID</string>
62
+ ```
63
+
64
+ You also need to add the URL scheme for your iOS client ID to the `ios/App/App/Info.plist` file:
65
+
66
+ ```xml
67
+ <key>CFBundleURLTypes</key>
68
+ <array>
69
+ <dict>
70
+ <key>CFBundleURLSchemes</key>
71
+ <array>
72
+ <string>com.googleusercontent.apps.YOUR_IOS_CLIENT_ID</string>
73
+ </array>
74
+ </dict>
75
+ </array>
76
+ ```
77
+
78
+ Replace `YOUR_IOS_CLIENT_ID` with the reversed client ID from the Google Cloud Console (e.g. `com.googleusercontent.apps.123456789-abc`).
79
+
80
+ ## Configuration
81
+
82
+ No configuration required for this plugin.
83
+
84
+ ## Usage
85
+
86
+ ```typescript
87
+ import { GoogleSignIn } from '@capawesome/capacitor-google-sign-in';
88
+ import { Capacitor } from '@capacitor/core';
89
+
90
+ const initialize = async () => {
91
+ await GoogleSignIn.initialize({
92
+ clientId: '123456789-abc.apps.googleusercontent.com',
93
+ scopes: ['https://www.googleapis.com/auth/userinfo.profile'],
94
+ });
95
+ };
96
+
97
+ const signIn = async () => {
98
+ const result = await GoogleSignIn.signIn();
99
+ console.log(result.idToken);
100
+ console.log(result.userId);
101
+ console.log(result.email);
102
+ console.log(result.displayName);
103
+ console.log(result.accessToken);
104
+ console.log(result.serverAuthCode);
105
+ };
106
+
107
+ const handleRedirectCallback = async () => {
108
+ if (Capacitor.getPlatform() !== 'web') {
109
+ return;
110
+ }
111
+ const result = await GoogleSignIn.handleRedirectCallback();
112
+ console.log(result.idToken);
113
+ console.log(result.userId);
114
+ console.log(result.email);
115
+ console.log(result.displayName);
116
+ console.log(result.accessToken);
117
+ console.log(result.serverAuthCode);
118
+ };
119
+
120
+ const signOut = async () => {
121
+ await GoogleSignIn.signOut();
122
+ };
123
+ ```
124
+
125
+ ## API
126
+
127
+ <docgen-index>
128
+
129
+ * [`handleRedirectCallback()`](#handleredirectcallback)
130
+ * [`initialize(...)`](#initialize)
131
+ * [`signIn(...)`](#signin)
132
+ * [`signOut()`](#signout)
133
+ * [Interfaces](#interfaces)
134
+
135
+ </docgen-index>
136
+
137
+ <docgen-api>
138
+ <!--Update the source file JSDoc comments and rerun docgen to update the docs below-->
139
+
140
+ ### handleRedirectCallback()
141
+
142
+ ```typescript
143
+ handleRedirectCallback() => Promise<SignInResult>
144
+ ```
145
+
146
+ Handle the redirect callback from the OAuth provider.
147
+
148
+ This method must be called when the app is redirected back from the OAuth provider.
149
+ It exchanges the authorization code for tokens and returns the sign-in result.
150
+
151
+ Only available on Web.
152
+
153
+ **Returns:** <code>Promise&lt;<a href="#signinresult">SignInResult</a>&gt;</code>
154
+
155
+ **Since:** 0.1.0
156
+
157
+ --------------------
158
+
159
+
160
+ ### initialize(...)
161
+
162
+ ```typescript
163
+ initialize(options: InitializeOptions) => Promise<void>
164
+ ```
165
+
166
+ Initialize the Google Sign-In plugin.
167
+
168
+ This method must be called once before all other methods.
169
+
170
+ | Param | Type |
171
+ | ------------- | --------------------------------------------------------------- |
172
+ | **`options`** | <code><a href="#initializeoptions">InitializeOptions</a></code> |
173
+
174
+ **Since:** 0.1.0
175
+
176
+ --------------------
177
+
178
+
179
+ ### signIn(...)
180
+
181
+ ```typescript
182
+ signIn(options?: SignInOptions | undefined) => Promise<SignInResult>
183
+ ```
184
+
185
+ Start the Google Sign-In flow.
186
+
187
+ On Web, this redirects to the Google OAuth authorization page.
188
+ The promise will never resolve on Web. After the user signs in,
189
+ the app will be redirected back to the `redirectUrl`.
190
+ Use `handleRedirectCallback()` to complete the sign-in flow.
191
+
192
+ | Param | Type |
193
+ | ------------- | ------------------------------------------------------- |
194
+ | **`options`** | <code><a href="#signinoptions">SignInOptions</a></code> |
195
+
196
+ **Returns:** <code>Promise&lt;<a href="#signinresult">SignInResult</a>&gt;</code>
197
+
198
+ **Since:** 0.1.0
199
+
200
+ --------------------
201
+
202
+
203
+ ### signOut()
204
+
205
+ ```typescript
206
+ signOut() => Promise<void>
207
+ ```
208
+
209
+ Sign out the current user.
210
+
211
+ On Android, this clears the credential state.
212
+ On iOS, this signs out from the Google Sign-In SDK.
213
+ On Web, this is a no-op.
214
+
215
+ **Since:** 0.1.0
216
+
217
+ --------------------
218
+
219
+
220
+ ### Interfaces
221
+
222
+
223
+ #### SignInResult
224
+
225
+ | Prop | Type | Description | Since |
226
+ | -------------------- | --------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----- |
227
+ | **`idToken`** | <code>string</code> | The ID token (JWT) returned by Google. This token can be sent to your backend for verification. | 0.1.0 |
228
+ | **`userId`** | <code>string</code> | The unique identifier of the user's Google Account. | 0.1.0 |
229
+ | **`email`** | <code>string \| null</code> | The user's email address. | 0.1.0 |
230
+ | **`displayName`** | <code>string \| null</code> | The user's display name (full name). | 0.1.0 |
231
+ | **`givenName`** | <code>string \| null</code> | The user's given name (first name). | 0.1.0 |
232
+ | **`familyName`** | <code>string \| null</code> | The user's family name (last name). | 0.1.0 |
233
+ | **`imageUrl`** | <code>string \| null</code> | The URL of the user's profile picture. | 0.1.0 |
234
+ | **`accessToken`** | <code>string \| null</code> | The access token for accessing Google APIs. Only available when `scopes` are configured in `initialize()`. | 0.1.0 |
235
+ | **`serverAuthCode`** | <code>string \| null</code> | The server auth code that can be exchanged on your backend for access and refresh tokens. Only available on Android and iOS when `scopes` are configured in `initialize()`. | 0.1.0 |
236
+
237
+
238
+ #### InitializeOptions
239
+
240
+ | Prop | Type | Description | Since |
241
+ | ----------------- | --------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----- |
242
+ | **`clientId`** | <code>string</code> | The web client ID from Google Cloud Console. On Android, this is passed as the server client ID to the Credential Manager API and the AuthorizationClient API. On iOS, this is used as the server client ID for the Google Sign-In SDK. On Web, this is used to initialize the Google Sign-In JavaScript API. **Attention**: This must be a web client ID on all platforms, even on Android and iOS. | 0.1.0 |
243
+ | **`redirectUrl`** | <code>string</code> | The URL to redirect to after the OAuth flow. Only available on Web. | 0.1.0 |
244
+ | **`scopes`** | <code>string[]</code> | The OAuth scopes to request. If provided, the plugin will request authorization in addition to authentication. This enables `accessToken` and `serverAuthCode` in the sign-in result. | 0.1.0 |
245
+
246
+
247
+ #### SignInOptions
248
+
249
+ | Prop | Type | Description | Since |
250
+ | ----------- | ------------------- | --------------------------------------------------------------------- | ----- |
251
+ | **`nonce`** | <code>string</code> | A nonce to prevent replay attacks. Only available on Android and Web. | 0.1.0 |
252
+
253
+ </docgen-api>
254
+
255
+ ## FAQ
256
+
257
+ ### What's the difference between this plugin and other Google Sign-In plugins?
258
+
259
+ This plugin is purpose-built for Google Sign-In and focuses on providing a clean and modern API with the latest platform features. Here are some of the key differences:
260
+
261
+ - **Cross-platform**: Supports Android, iOS, and Web.
262
+ - **Lightweight**: No unnecessary dependencies. Just Google Sign-In, nothing else.
263
+ - **No deprecated APIs**: Uses the latest platform APIs (Credential Manager on Android, Google Sign-In SDK on iOS).
264
+ - **Authentication + Authorization**: Supports both authentication (ID tokens) and authorization (access tokens, server auth codes) in a single flow.
265
+ - **Error codes**: Provides typed error codes for proper error handling.
266
+ - **Redirect flow on Web**: Uses a redirect-based OAuth flow instead of popups, resulting in a more reliable and user-friendly experience.
267
+
268
+ ## Changelog
269
+
270
+ See [CHANGELOG.md](https://github.com/capawesome-team/capacitor-plugins/blob/main/packages/google-sign-in/CHANGELOG.md).
271
+
272
+ ## License
273
+
274
+ See [LICENSE](https://github.com/capawesome-team/capacitor-plugins/blob/main/packages/google-sign-in/LICENSE).
275
+
276
+ [^1]: This project is not affiliated with, endorsed by, sponsored by, or approved by Google Inc. or any of their affiliates or subsidiaries.
@@ -0,0 +1,65 @@
1
+ ext {
2
+ junitVersion = project.hasProperty('junitVersion') ? rootProject.ext.junitVersion : '4.13.2'
3
+ androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.7.1'
4
+ androidxCredentialsVersion = project.hasProperty('androidxCredentialsVersion') ? rootProject.ext.androidxCredentialsVersion : '1.5.0'
5
+ androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.3.0'
6
+ androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.7.0'
7
+ googleIdVersion = project.hasProperty('googleIdVersion') ? rootProject.ext.googleIdVersion : '1.1.1'
8
+ playServicesAuthVersion = project.hasProperty('playServicesAuthVersion') ? rootProject.ext.playServicesAuthVersion : '21.5.0'
9
+ }
10
+
11
+ buildscript {
12
+ repositories {
13
+ google()
14
+ mavenCentral()
15
+ }
16
+ dependencies {
17
+ classpath 'com.android.tools.build:gradle:8.13.0'
18
+ }
19
+ }
20
+
21
+ apply plugin: 'com.android.library'
22
+
23
+ android {
24
+ namespace = "io.capawesome.capacitorjs.plugins.googlesignin"
25
+ compileSdk = project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 36
26
+ defaultConfig {
27
+ minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 24
28
+ targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 36
29
+ versionCode 1
30
+ versionName "1.0"
31
+ testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
32
+ }
33
+ buildTypes {
34
+ release {
35
+ minifyEnabled false
36
+ proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
37
+ }
38
+ }
39
+ lintOptions {
40
+ abortOnError = false
41
+ }
42
+ compileOptions {
43
+ sourceCompatibility JavaVersion.VERSION_21
44
+ targetCompatibility JavaVersion.VERSION_21
45
+ }
46
+ }
47
+
48
+ repositories {
49
+ google()
50
+ mavenCentral()
51
+ }
52
+
53
+
54
+ dependencies {
55
+ implementation fileTree(dir: 'libs', include: ['*.jar'])
56
+ implementation project(':capacitor-android')
57
+ implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
58
+ implementation "androidx.credentials:credentials:$androidxCredentialsVersion"
59
+ implementation "androidx.credentials:credentials-play-services-auth:$androidxCredentialsVersion"
60
+ implementation "com.google.android.libraries.identity.googleid:googleid:$googleIdVersion"
61
+ implementation "com.google.android.gms:play-services-auth:$playServicesAuthVersion"
62
+ testImplementation "junit:junit:$junitVersion"
63
+ androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
64
+ androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
65
+ }
@@ -0,0 +1,2 @@
1
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android">
2
+ </manifest>