Socket
Socket
Sign inDemoInstall

@hristo2612/capacitor-google-auth

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@hristo2612/capacitor-google-auth

Capacitor Plugin for authenticating Google Users


Version published
Weekly downloads
2
increased by100%
Maintainers
1
Weekly downloads
 
Created
Source

CapacitorGoogleAuth

Capacitor plugin for Google Auth. ( This is a fixed version of @codetrix-studio/capacitor-google-auth for Capacitor 3+

Contributions

PRs are welcome and much appreciated that keeps this plugin up to date with Capacitor and official Google Auth platform library feature parity.

Try to follow good code practices. You can even help keeping the included demo updated.

PRs for features that are not aligned with the official Google Auth library are discouraged.

(We are beginner-friendly here)

Install

1. Install package
npm i @hristo2612/capacitor-google-auth
2. Update capacitor deps
npx cap update

Usage

Integration For the Browser

Add clientId meta tag to head in index.html.

<meta name="google-signin-client_id" content="{your client id here}" />

Register plugin and manually initialize

import { GoogleAuth } from '@codetrix-studio/capacitor-google-auth';

// use hook after platform dom ready
GoogleAuth.init();

Use it

GoogleAuth.signIn();
AngularFire & Firebase

init hook & sign in function

import { GoogleAuth } from '@hristo2612/capacitor-google-auth';
import { AngularFireAuth } from '@angular/fire/auth';
import firebase from 'firebase/app';
import 'firebase/auth';

// app.component.ts
constructor(private afAuth: AngularFireAuth) {
  this.initializeApp();
}

initializeApp() {
  this.platform.ready().then(() => {
    GoogleAuth.init();
  });
}

async googleSignIn() {
  let googleUser = await GoogleAuth.signIn();
  const credential = firebase.auth.GoogleAuthProvider.credential(googleUser.authentication.idToken);
  return this.afAuth.signInWithCredential(credential);
}

iOS Integration

Make sure you have GoogleService-Info.plist with CLIENT_ID

Add REVERSED_CLIENT_ID as url scheme to Info.plist

Android Integration

Inside your strings.xml

<resources>
  <string name="server_client_id">Your Web Client Key ( Same as the one in the index.html meta tag )</string>
</resources>

Import package inside your MainActivity

import com.hristo2612.capacitor.google.auth;

Register plugin inside your MainActivity.java

public class MainActivity extends BridgeActivity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        registerPlugin(GoogleAuth.class);
    }
}

Configure

Provide configuration in root capacitor.config.json

{
  "plugins": {
    "GoogleAuth": {
      "scopes": ["profile", "email"],
      "serverClientId": "xxxxxx-xxxxxxxxxxxxxxxxxx.apps.googleusercontent.com",
      "forceCodeForRefreshToken": true
    }
  }
}

Note : forceCodeForRefreshToken force user to select email address to regenerate AuthCode used to get a valid refreshtoken (work on iOS and Android) (This is used for offline access and serverside handling)

Keywords

FAQs

Package last updated on 22 Aug 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc