Client-side Google authentication provider for sensenet
npm install @sensenet/authentication-googlebash
Yarn
yarn add @sensenet/authentication-google
NPM
npm install @sensenet/authentication-google
`
Usage
$3
- sensenet 7.0 with an installed Google OAuth provider
- Google API Console project
- _(optional)_ Google Platform Library or another Google OAuth component that can retrieve _id_token_
$3
You can set up the Provider after creating your repository singleton with the addGoogleAuth method
`ts
import { Repository } from '@sensenet/client-core'
import { JwtService } from '@sensenet/authentication-jwt'
import { addGoogleAuth } from '@sensenet/authentication-google'
const repo = new Repository()
const jwt = new JwtService(repo)
const googleOauthProvider = addGoogleAuth(jwt, { clientId: '' })
`
$3
In your login component, you can use the following snippet. If you don't provide an _id_token_ from an external component, the package will try to retrieve it using a popup window (in that case you have to enable popups and add a callback pointing to your window's origin)
`ts
// an example login method with an optional idToken:
async Login(idToken?: string){
try {
await googleOauthProvider.login(idToken);
console.log('Logged in');
} catch (error) {
console.warn('Error during login', error);
}
}
``