Coder Social home page Coder Social logo

mircoba / capacitorgoogleauth Goto Github PK

View Code? Open in Web Editor NEW

This project forked from codetrixstudio/capacitorgoogleauth

0.0 0.0 0.0 641 KB

Capacitor plugin for Google Auth. Lightweight & no dependencies.

License: MIT License

Ruby 6.01% Java 29.91% Objective-C 4.44% Swift 31.67% JavaScript 1.47% TypeScript 26.50%

capacitorgoogleauth's Introduction

CapacitorGoogleAuth

Capacitor plugin for Google Auth.

Install

npm i --save @codetrix-studio/capacitor-google-auth

npx cap update

WEB

Add clientId meta tag to head.

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

Register the plugin by importing it.

import "@codetrix-studio/capacitor-google-auth";

Use it

import { Plugins } from '@capacitor/core';
Plugins.GoogleAuth.signIn();

AngularFire2

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

iOS

Make sure you have GoogleService-Info.plist with CLIENT_ID

Add REVERSED_CLIENT_ID as url scheme to Info.plist

Android

Inside your strings.xml

<resources>
  <string name="server_client_id">Your Web Client Key</string>
</resources>

Register plugin inside your MainActivity.onCreate

this.init(savedInstanceState, new ArrayList<Class<? extends Plugin>>() {{
  add(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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.