{"id":13448501,"url":"https://github.com/CodetrixStudio/CapacitorGoogleAuth","last_synced_at":"2025-03-22T09:31:25.470Z","repository":{"id":38431083,"uuid":"187340603","full_name":"CodetrixStudio/CapacitorGoogleAuth","owner":"CodetrixStudio","description":"Capacitor plugin for Google Auth. Lightweight \u0026 no dependencies.","archived":false,"fork":false,"pushed_at":"2025-01-11T00:12:53.000Z","size":1293,"stargazers_count":297,"open_issues_count":131,"forks_count":168,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-03-16T21:02:00.596Z","etag":null,"topics":["android","authentication","capacitor","capacitor-plugin","google","ios","pwa","web"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/CodetrixStudio.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-05-18T09:46:21.000Z","updated_at":"2025-03-05T09:47:32.000Z","dependencies_parsed_at":"2023-11-29T09:46:19.599Z","dependency_job_id":"460248ef-d7c0-4a33-8c45-be9adc9e7f7e","html_url":"https://github.com/CodetrixStudio/CapacitorGoogleAuth","commit_stats":{"total_commits":117,"total_committers":23,"mean_commits":5.086956521739131,"dds":0.6752136752136753,"last_synced_commit":"41ece7d6ff97643feb316df0113342a00d0d7717"},"previous_names":[],"tags_count":42,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CodetrixStudio%2FCapacitorGoogleAuth","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CodetrixStudio%2FCapacitorGoogleAuth/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CodetrixStudio%2FCapacitorGoogleAuth/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CodetrixStudio%2FCapacitorGoogleAuth/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/CodetrixStudio","download_url":"https://codeload.github.com/CodetrixStudio/CapacitorGoogleAuth/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244937751,"owners_count":20535124,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","authentication","capacitor","capacitor-plugin","google","ios","pwa","web"],"created_at":"2024-07-31T05:01:47.378Z","updated_at":"2025-03-22T09:31:25.464Z","avatar_url":"https://github.com/CodetrixStudio.png","language":"TypeScript","readme":"\u003e [!WARNING]\n\u003e This plugin is \"virtually\" archived as there no way to reach the author in any medium\n\u003e Please use: https://github.com/Cap-go/capacitor-social-login as alternative follow [**migration here**](https://github.com/Cap-go/capacitor-social-login/blob/main/MIGRATION_CODETRIX.md)\n\n\u003ch1 align=\"center\"\u003eCapacitorGoogleAuth\u003c/h1\u003e\n\u003cp align=\"center\"\u003e\u003cstrong\u003e\u003ccode\u003e@codetrix-studio/capacitor-google-auth\u003c/code\u003e\u003c/strong\u003e\u003c/p\u003e\n\u003cp align=\"center\"\u003e\u003cstrong\u003eCAPACITOR 6\u003c/strong\u003e\u003c/p\u003e\n\u003cp align=\"center\"\u003e\nCapacitor plugin for Google Auth.\n\u003c/p\u003e\n\u003cbr\u003e\n\u003cp align=\"center\"\u003e\n\u003ca href=\"https://www.npmjs.com/package/@codetrix-studio/capacitor-google-auth\"\u003e\u003cimg alt=\"npm\" src=\"https://img.shields.io/npm/v/@codetrix-studio/capacitor-google-auth\"\u003e\u003c/a\u003e \u003ca href=\"https://www.npmjs.com/package/@codetrix-studio/capacitor-google-auth\"\u003e\u003cimg alt=\"npm\" src=\"https://img.shields.io/npm/dt/@codetrix-studio/capacitor-google-auth\"\u003e\u003c/a\u003e \u003ca href=\"https://www.npmjs.com/package/@codetrix-studio/capacitor-google-auth\"\u003e\u003cimg alt=\"npm\" src=\"https://img.shields.io/npm/dw/@codetrix-studio/capacitor-google-auth\"\u003e\u003c/a\u003e \u003ca href=\"https://libraries.io/npm/@codetrix-studio%2Fcapacitor-google-auth\"\u003e\u003cimg alt=\"Dependents (via libraries.io)\" src=\"https://img.shields.io/librariesio/dependents/npm/@codetrix-studio/capacitor-google-auth\"\u003e\u003c/a\u003e \u003ca href=\"https://packagephobia.com/result?p=@codetrix-studio/capacitor-google-auth\"\u003e\u003cimg alt=\"install size\" src=\"https://packagephobia.com/badge?p=@codetrix-studio/capacitor-google-auth\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n## Breaking change in V6\n\nIn the v6 version, `clientId` in the initialize method is used in priority over other places you could set up. If before you were using this only on the web, unset it on mobile. Or set it conditionally to replicate old behavior.\n\n## Contributions\n\nPRs are welcome and much appreciated that keeps this plugin up to date with Capacitor and official Google Auth platform library feature parity.\n\nTry to follow good code practices. You can even help keeping the included demo updated.\n\nPRs for features that are not aligned with the official Google Auth library are discouraged.\n\n(We are beginner-friendly here)\n\n## Install\n\n#### 1. Install package\n\n```sh\nnpm i --save @codetrix-studio/capacitor-google-auth\n\n# pnpm \npnpm add @codetrix-studio/capacitor-google-auth\n\n# yarn \nyarn add @codetrix-studio/capacitor-google-auth\n```\n\n#### 2. Update capacitor deps\n\n```sh\nnpx cap update\n```\n\n## Updating\n\nIf need migrate to different Capacitor versions [see instruction for migrate plugin to new version](#migration-guide).\n\n## Usage\n\n### WEB\n\nRegister plugin and manually initialize\n\n```ts\nimport { GoogleAuth } from '@codetrix-studio/capacitor-google-auth';\n\n// use hook after platform dom ready\nGoogleAuth.initialize({\n  clientId: 'CLIENT_ID.apps.googleusercontent.com',\n  scopes: ['profile', 'email'],\n  grantOfflineAccess: true,\n});\n```\n\nor if need use meta tags (Optional):\n\n```html\n\u003cmeta name=\"google-signin-client_id\" content=\"{your client id here}\" /\u003e\n\u003cmeta name=\"google-signin-scope\" content=\"profile email\" /\u003e\n```\n\n#### Options\n\n- `clientId` - The app's client ID, found and created in the Google Developers Console.\n- `scopes` – same as [Configure](#Configure) scopes\n- `grantOfflineAccess` – boolean, default `false`, Set if your application needs to refresh access tokens when the user is not present at the browser.\n\nUse it\n\n```ts\nGoogleAuth.signIn();\n```\n\n#### Angular\n\ninit hook\n\n```ts\n// app.component.ts\nconstructor() {\n  this.initializeApp();\n}\n\ninitializeApp() {\n  this.platform.ready().then(() =\u003e {\n    GoogleAuth.initialize()\n  })\n}\n```\n\nsign in function\n\n```ts\nimport { GoogleAuth } from \"@codetrix-studio/capacitor-google-auth\";\nimport { Auth, GoogleAuthProvider, signInWithCredential } from '@angular/fire/auth';\n\nasync googleSignIn() {\n  let googleUser = await GoogleAuth.signIn();\n\n  /*\n    If you use Firebase you can forward and use the logged in Google user like this:\n  */\n  constructor(private auth: Auth){}\n\n  const googleUser = await GoogleAuth.signIn();\n  const _credential = GoogleAuthProvider.credential(googleUser.authentication.idToken);\n  return signInWithCredential(this.auth, _credential);\n}\n```\n\n#### Vue 3\n\n```vue\n\u003cscript setup lang=\"ts\"\u003e\nimport { defineComponent, onMounted } from 'vue';\nimport { GoogleAuth } from '@codetrix-studio/capacitor-google-auth';\n\nonMounted(() =\u003e {\n  GoogleAuth.initialize();\n});\n\nasync function logIn() {\n  const response = await GoogleAuth.signIn();\n  console.log(response);\n}\n\u003c/script\u003e\n```\n\nor see more [CapacitorGoogleAuth-Vue3-example](https://github.com/reslear/CapacitorGoogleAuth-Vue3-example)\n\n### iOS\n\n1. Create in Google cloud console credential **Client ID for iOS** and get **Client ID** and **iOS URL scheme**\n\n2. Add **identifier** `REVERSED_CLIENT_ID` as **URL schemes** to `Info.plist` from **iOS URL scheme**\u003cbr\u003e\n   (Xcode: App - Targets/App - Info - URL Types, click plus icon)\n\n3. Set **Client ID** one of the ways (by order of importance in the plugin):\n   1. Set `clientId` in initialize method\n   2. Set `iosClientId` in `capacitor.config.json`\n   3. Set `clientId` in `capacitor.config.json`\n   4. Set `CLIENT_ID` in `GoogleService-Info.plist`\n\n### Android\n\nSet **Client ID** (by order of importance in the plugin):\n1. Set `clientId` in initialize method\n2. Set `androidClientId` in `capacitor.config.json`\n3. Set `clientId` in `capacitor.config.json`\n4. Set `server_client_id` in `strings.xml`\n\n```xml\n\u003cresources\u003e\n  \u003cstring name=\"server_client_id\"\u003eYour Web Client Key\u003c/string\u003e\n\u003c/resources\u003e\n```\n\nChanging Play Services Auth version (Optional) :\n\nThis plugin uses `com.google.android.gms:play-services-auth:21.2.0` by default, you can override it providing `gmsPlayServicesAuthVersion` at `variables.gradle`\n\n**Refresh method**\n\nThis method should be called when the app is initialized to establish if the user is currently logged in. If true, the method will return an accessToken, idToken and an empty refreshToken.\n```ts\ncheckLoggedIn() {\n    GoogleAuth.refresh()\n        .then((data) =\u003e {\n            if (data.accessToken) {\n                this.currentTokens = data;\n            }\n        })\n        .catch((error) =\u003e {\n            if (error.type === 'userLoggedOut') {\n                this.signin()\n            }\n        });\n}\n```\n\n## Configure\n\n| Name                     | Type     | Description                                                                                                                   |\n| ------------------------ | -------- | ----------------------------------------------------------------------------------------------------------------------------- |\n| clientId                 | string   | The app's client ID, found and created in the Google Developers Console.                                                      |\n| iosClientId              | string   | Specific client ID key for iOS                                                                                                |\n| androidClientId          | string   | Specific client ID key for Android                                                                                            |\n| scopes                   | string[] | Scopes that you might need to request to access Google APIs\u003cbr\u003ehttps://developers.google.com/identity/protocols/oauth2/scopes |\n| serverClientId           | string   | This ClientId used for offline access and server side handling                                                                |\n| forceCodeForRefreshToken | boolean  | Force user to select email address to regenerate AuthCode \u003cbr\u003eused to get a valid refreshtoken (work on iOS and Android)      |\n\nProvide configuration in root `capacitor.config.json`\n\n```json\n{\n  \"plugins\": {\n    \"GoogleAuth\": {\n      \"scopes\": [\"profile\", \"email\"],\n      \"serverClientId\": \"xxxxxx-xxxxxxxxxxxxxxxxxx.apps.googleusercontent.com\",\n      \"forceCodeForRefreshToken\": true\n    }\n  }\n}\n```\n\nor in `capacitor.config.ts`\n\n```ts\n/// \u003creference types=\"'@codetrix-studio/capacitor-google-auth'\" /\u003e\n\nconst config: CapacitorConfig = {\n  plugins: {\n    GoogleAuth: {\n      scopes: ['profile', 'email'],\n      serverClientId: 'xxxxxx-xxxxxxxxxxxxxxxxxx.apps.googleusercontent.com',\n      forceCodeForRefreshToken: true,\n    },\n  },\n};\n\nexport default config;\n```\n#### Note: scopes can be configured under \u003ccode\u003e\u003ca href=\"#initialize\"\u003einitialize\u003c/a\u003e\u003c/code\u003e function.\n\n## API\n\n\u003cdocgen-index\u003e\n\n* [`initialize(...)`](#initialize)\n* [`signIn()`](#signin)\n* [`refresh()`](#refresh)\n* [`signOut()`](#signout)\n* [Interfaces](#interfaces)\n\n\u003c/docgen-index\u003e\n\u003cdocgen-api\u003e\n\u003c!--Update the source file JSDoc comments and rerun docgen to update the docs below--\u003e\n\n### initialize(...)\n\n```typescript\ninitialize(options?: InitOptions) =\u003e void\n```\n\nInitializes the GoogleAuthPlugin, loading the gapi library and setting up the plugin.\n\n| Param         | Type                                                | Description                        |\n| ------------- | --------------------------------------------------- | ---------------------------------- |\n| **`options`** | \u003ccode\u003e\u003ca href=\"#initoptions\"\u003eInitOptions\u003c/a\u003e\u003c/code\u003e | - Optional initialization options. |\n\n**Since:** 3.1.0\n\n--------------------\n\n\n### signIn()\n\n```typescript\nsignIn() =\u003e Promise\u003cUser\u003e\n```\n\nInitiates the sign-in process and returns a Promise that resolves with the user information.\n\n**Returns:** \u003ccode\u003ePromise\u0026lt;\u003ca href=\"#user\"\u003eUser\u003c/a\u003e\u0026gt;\u003c/code\u003e\n\n--------------------\n\n\n### refresh()\n\n```typescript\nrefresh() =\u003e Promise\u003cAuthentication\u003e\n```\n\nRefreshes the authentication token and returns a Promise that resolves with the updated authentication details.\n\n**Returns:** \u003ccode\u003ePromise\u0026lt;\u003ca href=\"#authentication\"\u003eAuthentication\u003c/a\u003e\u0026gt;\u003c/code\u003e\n\n--------------------\n\n\n### signOut()\n\n```typescript\nsignOut() =\u003e Promise\u003cany\u003e\n```\n\nSigns out the user and returns a Promise.\n\n**Returns:** \u003ccode\u003ePromise\u0026lt;any\u0026gt;\u003c/code\u003e\n\n--------------------\n\n\n### Interfaces\n\n\n#### InitOptions\n\n| Prop                     | Type                  | Description                                                                                                                                      | Default            | Since      |\n| ------------------------ | --------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------ | ---------- |\n| **`clientId`**           | \u003ccode\u003estring\u003c/code\u003e   | The app's client ID, found and created in the Google Developers Console. Common for Android or iOS. The default is defined in the configuration. |                    | 3.1.0      |\n| **`scopes`**             | \u003ccode\u003estring[]\u003c/code\u003e | Specifies the scopes required for accessing Google APIs The default is defined in the configuration.                                             |                    | 3.4.0-rc.4 |\n| **`grantOfflineAccess`** | \u003ccode\u003eboolean\u003c/code\u003e  | Set if your application needs to refresh access tokens when the user is not present at the browser. In response use `serverAuthCode` key         | \u003ccode\u003efalse\u003c/code\u003e | 3.1.0      |\n\n\n#### User\n\n| Prop                 | Type                                                      | Description                                                         |\n| -------------------- | --------------------------------------------------------- | ------------------------------------------------------------------- |\n| **`id`**             | \u003ccode\u003estring\u003c/code\u003e                                       | The unique identifier for the user.                                 |\n| **`email`**          | \u003ccode\u003estring\u003c/code\u003e                                       | The email address associated with the user.                         |\n| **`name`**           | \u003ccode\u003estring\u003c/code\u003e                                       | The user's full name.                                               |\n| **`familyName`**     | \u003ccode\u003estring\u003c/code\u003e                                       | The family name (last name) of the user.                            |\n| **`givenName`**      | \u003ccode\u003estring\u003c/code\u003e                                       | The given name (first name) of the user.                            |\n| **`imageUrl`**       | \u003ccode\u003estring\u003c/code\u003e                                       | The URL of the user's profile picture.                              |\n| **`serverAuthCode`** | \u003ccode\u003estring\u003c/code\u003e                                       | The server authentication code.                                     |\n| **`authentication`** | \u003ccode\u003e\u003ca href=\"#authentication\"\u003eAuthentication\u003c/a\u003e\u003c/code\u003e | The authentication details including access, refresh and ID tokens. |\n\n\n#### Authentication\n\n| Prop               | Type                | Description                                      |\n| ------------------ | ------------------- | ------------------------------------------------ |\n| **`accessToken`**  | \u003ccode\u003estring\u003c/code\u003e | The access token obtained during authentication. |\n| **`idToken`**      | \u003ccode\u003estring\u003c/code\u003e | The ID token obtained during authentication.     |\n| **`refreshToken`** | \u003ccode\u003estring\u003c/code\u003e | The refresh token.                               |\n\n\u003c/docgen-api\u003e\n\n## Migration guide\n\n#### Migrate from 3.3.x to 3.4.x\n\nInstall version 3.4.x:\n\n```sh\nnpm i --save @codetrix-studio/capacitor-google-auth@^3.4\n```\n\nFollow instruction for you project [Updating to Capacitor 6](https://capacitorjs.com/docs/next/updating/6-0).\n\n#### Migrate from 3.2.x to 3.3.x\n\nInstall version 3.3.x:\n\n```sh\nnpm i --save @codetrix-studio/capacitor-google-auth^3.3\n```\n\nFollow instruction for you project [Updating from Capacitor 4 to Capacitor 5](https://capacitorjs.com/docs/updating/5-0).\n\n#### Migrate from 3.2.1 to 3.2.2\n\nfor `Android` in file `MainActivity.onCreate`\n\n```diff\n- this.init(savedInstanceState, new ArrayList\u003cClass\u003c? extends Plugin\u003e\u003e() {{\n-   add(GoogleAuth.class);\n- }});\n+ this.registerPlugin(GoogleAuth.class);\n```\n\n#### Migrate from 3.1.x to 3.2.x\n\nInstall version 3.2.x:\n\n```sh\nnpm i --save @codetrix-studio/capacitor-google-auth^3.2\n```\n\nFollow instruction for you project [Updating from Capacitor 3 to Capacitor 4](https://capacitorjs.com/docs/updating/4-0).\n\n#### Migrate from 3.0.2 to 3.1.0\n\n```diff\n- GoogleAuth.init()\n+ GoogleAuth.initialize()\n```\n\n#### Migrate from 2 to 3\n\nInstall version 3.x.x:\n\n```sh\nnpm i --save @codetrix-studio/capacitor-google-auth^3.0\n```\n\nAfter [migrate to Capcitor 3](https://capacitorjs.com/docs/updating/3-0) updating you projects, see diff:\n\n##### WEB\n\n```diff\n- import \"@codetrix-studio/capacitor-google-auth\";\n- import { Plugins } from '@capacitor/core';\n+ import { GoogleAuth } from '@codetrix-studio/capacitor-google-auth'\n\n- Plugins.GoogleAuth.signIn();\n+ GoogleAuth.init()\n+ GoogleAuth.signIn()\n```\n\n#### Migrate from 1 to 2\n\nInstall version 2.x.x:\n\n```sh\nnpm i --save @codetrix-studio/capacitor-google-auth@2\n```\n\nfor capacitor 2.x.x use [instruction](https://github.com/CodetrixStudio/CapacitorGoogleAuth/blob/79129ab37288f5f5d0bb9a568a95890e852cebc2/README.md)\n\n## License\n\n[MIT](./LICENSE)\n","funding_links":[],"categories":["Swift","Java","Plugins","Other plugins"],"sub_categories":["Community Plugins","Specialized Hardware"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FCodetrixStudio%2FCapacitorGoogleAuth","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FCodetrixStudio%2FCapacitorGoogleAuth","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FCodetrixStudio%2FCapacitorGoogleAuth/lists"}