Google Auth plugin for capacitor.
npm install @boeto/capacitor-google-authbash
npm i --save @codetrix-studio/capacitor-google-authnpx cap update
`$3
Add clientId meta tag to head.
`html
`Register the plugin by importing it.
`ts
import "@codetrix-studio/capacitor-google-auth";
`Use it
`ts
import { Plugins } from '@capacitor/core';
Plugins.GoogleAuth.signIn();
`$3
`ts
async googleSignIn() {
let googleUser = await Plugins.GoogleAuth.signIn();
const credential = auth.GoogleAuthProvider.credential(googleUser.authentication.idToken);
return this.afAuth.auth.signInAndRetrieveDataWithCredential(credential);
}
`$3
Make sure you have GoogleService-Info.plist with CLIENT_IDAdd
REVERSED_CLIENT_ID as url scheme to Info.plist$3
Inside your strings.xml
`xml
Your Web Client Key
`Import package inside your
MainActivity
`java
import com.codetrixstudio.capacitor.GoogleAuth.GoogleAuth;
`Register plugin inside your
MainActivity.onCreate
`java
this.init(savedInstanceState, new ArrayList>() {{
add(GoogleAuth.class);
}});
`$3
Provide configuration in root capacitor.config.json
`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)