sn-client-auth-google
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

sn-client-auth-google

Gitter chat Build Status codecov License Commitizen friendly Greenkeeper badge

This package contains a client-side Google Oauth2 authentication provider for sensenet ECM through sn-client-js

Installation with node and npm

To install the latest version run

npm install --save sn-client-js

Usage

Prerequisites

Setup

You can set up the Provider after creating your repository singleton with the AddGoogleAuth method

import { Repository } from 'sn-client-js'
import { AddGoogleAuth } from 'sn-client-auth-google';
 
const myRepository = new Repository.SnRepository();
 
AddGoogleAuth(myRepository, {
     ClientId: myGoogleClientId
});

Login

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)

// an example login method with an optional idToken:
async Login(idToken?: string){
 try {
     await myRepository.Authentication.GetOauthProvider(GoogleOauthProvider).Login(idToken);
     console.log('Logged in');
 } catch (error) {
    console.warn('Error during login', error);
 }
}

Package Sidebar

Install

npm i sn-client-auth-google

Weekly Downloads

1

Version

1.0.0

License

GPL-2.0

Last publish

Collaborators

  • gallayl