Socket
Socket
Sign inDemoInstall

@attractor/microauth-google

Package Overview
Dependencies
71
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @attractor/microauth-google

Google oauth for micro


Version published
Maintainers
1
Install size
45.4 MB
Created

Readme

Source

microauth-google

Google oauth for micro

Build Status XO code style Greenkeeper badge

Add google authentication to your micro in few lines of code.

Inspired by Dmitry Pavlovsky microauth-github

Installation

npm install --save microauth-google
# or
yarn add microauth-google

Usage

app.js

const { send } = require('micro');
const microAuthGoogle = require('microauth-google');

const options = {
  clientId: 'CLIENT_ID',
  clientSecret: 'CLIENT_SECRET',
  callbackUrl: 'http://localhost:3000/auth/google/callback',
  path: '/auth/google',
  scope: 'https://www.googleapis.com/auth/plus.me'
};

const googleAuth = microAuthGoogle(options);

// third `auth` argument will provide error or result of authentication
// so it will {err: errorObject} or {result: {
//  provider: 'google',
//  accessToken: 'blahblah',
//  info: userInfo,
//  tokens: {Object with needed tokens to reuse with Google's OAuth2 instance}
// }}
module.exports = googleAuth(async (req, res, auth) => {

  if (!auth) {
    return send(res, 404, 'Not Found');
  }

  if (auth.err) {
    // Error handler
    return send(res, 403, 'Forbidden');
  }

  return `Hello ${auth.result.info.displayName}`;
});

Run:

micro app.js

Now visit http://localhost:3000/auth/google

Author

Rui Pedro Lima

FAQs

Last updated on 02 May 2019

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc