yauth-google

0.1.1 • Public • Published

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

Readme

Keywords

none

Package Sidebar

Install

npm i yauth-google

Weekly Downloads

3

Version

0.1.1

License

MIT

Unpacked Size

11.6 kB

Total Files

8

Last publish

Collaborators

  • frytg