New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

google-oauth-middleware

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

google-oauth-middleware

Express/connect middleware to authenticate with Google OAuth. No Passport pre-req.

  • 1.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

google-oauth-middleware

Express/connect middleware to authenticate with Google OAuth. No Passport pre-req.

This is better than passport in some cases such as needing to authenticate multiple Google accounts to use.

Install

npm i "google-oauth-middleware"

Usage

// the redirect path
const redirectPath = '/auth/google/callback';
const creds = {
    "clientId": "CLIENT_ID",
    "clientSecret": "CLIENT_SECRET",
    "redirectUri": `http://example.com${redirectPath}`
};

// setup the authenticator
const googleOAuth = require('google-oauth-middleware')(creds,
    async (credentials, profile, next) => {
        // store creds in db or however you want to use them
        GoogleAccount
            .addAsync(credentials, profile)
            .then(() => next(), next);
    }
);

// redirects to Google OAuth Consent Screen
// you can also define multiple .authenticate(scope)
// to authenticate with different scopes
app.get('/addGoogleAccount', googleOAuth.authenticate({
    scope: [
        'profile',
        'email',
        'openid',
        // add your scopes here
    ]
}));

// this is triggered on authentication from Google
app.get(redirectPath,
    // this triggers the authenticator
    googleOAuth.authenticate(),

    // success
    (req, res, next) => {
        // do something on success
    },

    // fail (this will be triggered when error handling
    // the credentials in the googleOAuth i.e. adding to db)
    (err, req, res, next) => {
        // handle error here somehow
    }
);

Keywords

FAQs

Package last updated on 14 Jul 2019

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc