1.0.4 • Published 6 years ago
@coolgk/google-sign-in v1.0.4
@coolgk/google-sign-in
a javascript / typescript module
npm install @coolgk/google-sign-in
google sign in module which verifies id token and returns account data
Report bugs here: https://github.com/coolgk/node-utils/issues
Examples
const { GoogleSignIn } = require('@coolgk/google-sign-in');
// OR
// import { GoogleSignIn } from '@coolgk/google-sign-in';
const googleSignIn = new GoogleSignIn({
clientId: '......'
});
const invalidToken = '...';
const validToken = '...';
(async () => {
const account1 = await googleSignIn.verify(invalidToken);
console.log(account1); // false
const account2 = await googleSignIn.verify(validToken);
console.log(account2);
// {
// azp: '...',
// aud: '...',
// sub: '123123123',
// email: 'abc@exmaple.com',
// email_verified: true,
// at_hash: 'asdfasdfasdfasdfa',
// exp: 1520633389,
// iss: 'accounts.google.com',
// jti: 'qfwfasdfasdfasdfasdfasdfasdfadsf',
// iat: 1520629789,
// name: 'first last',
// picture: 'https://lh6.googleusercontent.com/.../photo.jpg',
// given_name: 'first',
// family_name: 'last',
// locale: 'en-GB'
// }
})()
GoogleSignIn
Kind: global class
Export:
- GoogleSignIn
- instance
- .verify(token) ⇒ Promise.<(boolean|object)>
- static
- instance
googleSignIn.verify(token) ⇒ Promise.<(boolean|object)>
Kind: instance method of GoogleSignIn
Returns: Promise.<(boolean|object)> - - false if id token is invalid otherwise returns account data
Param | Type | Description |
---|---|---|
token | string | google id token string |
GoogleSignIn.GoogleSignIn
Kind: static class of GoogleSignIn
new GoogleSignIn(options)
Param | Type | Description |
---|---|---|
options | object | |
options.clientId | string | google client id |