0.1.1 • Published 5 years ago

yauth-google v0.1.1

Weekly downloads
21
License
MIT
Repository
github
Last release
5 years ago

yAuth-google

LICENSE SIZE VERSION

Integrate Google OAuth to serverless with Datastore

ADVANTAGES

Enable logins to serverless pages, dashboard and more using Google OAuth.

INSTALL

  • Add package to your project npm i yauth-google --save
  • Load yAuth-google into your project providing credentials and settings
const yAuthGoogle			= require('yauth-google')
const yAuth					= new yAuthGoogle({
		clientId:			'SOMETHING',
		clientSecret:		'SOMETHING',
		redirectUri:		'https://SOMETHING.cloudfunctions.net',
		baseUri:			'/SOMETHING/',
		datastoreProject:	'SOMETHING',
		datastoreNamespace:	'serverlessGoogleAuth',
		datastoreKey:		__dirname + '/keys/SOMETHING.json' })
  • This also only works if you're running the serverless function through express middleware. In my case something like this:
const ejs		= require('ejs')
const path		= require('path')
const functions	= require('firebase-functions')
const admin		= require('firebase-admin')
const express	= require('express')
const app 		= express()
const cookieParser	= require('cookie-parser')
// initialize the firebase/cloudfunctions App
admin.initializeApp();
app.use(cookieParser())
app.set('json spaces', 2)

// Route your express requests
app.get('/', (req, res) => {
	index(req, res); });
app.get('/something', (req, res) => {
	something(req, res); });

// Handle 404s
app.use(async function(req, res) {
	var html = await ejs.renderFile(__dirname + '/views/error.ejs', {})
	res.status(404).send(html) })
  • Now when you're calling the requested function and require user log in, verify their credentials:
const authResponse = await yAuth.requestHandler(req, res)
if(authResponse === false) { return false }
  • If you get past return false, you can use authResponse where the user profile will be returned
  • You should wrap your functions in try {...} catch… sections, since problems with yAuth will be rejected Promises.

LICENSE

This project is licensed under the MIT License - see the LICENSE file for details

AUTHOR

0.1.1

5 years ago

0.1.0

5 years ago

0.0.17

5 years ago

0.0.16

5 years ago

0.0.15

5 years ago

0.0.14

5 years ago

0.0.13

5 years ago

0.0.12

5 years ago

0.0.11

5 years ago

0.0.10

5 years ago

0.0.9

5 years ago

0.0.8

5 years ago

0.0.7

5 years ago

0.0.6

5 years ago

0.0.5

5 years ago

0.0.4

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago