1.0.2 • Published 5 years ago

google-idtoken-auth v1.0.2

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

google-token-auth

Codacy Badge

Node.js middleware to validate Google ID Tokens in the backend server. Validade the request token, get all the Google ID Token fields and populate the req.googleProfileInfo.

Installation

$ npm install google-idtoken-auth

Options

PropertieTypeDefaultRequiredDescription
clientIdStringtrueSpecify the Google Client ID
tokenHeaderNameStringx-googleid-tokenfalseCustom header name to retrievi the Google ID Token
gSuiteDomainsArrayfalseSpecify a G Suite domain

Example

var express = require('express');
var googleAuth = require('google-idtoken-auth');

var googleTokenVerifier = googleAuth.googleIdTokenVerifier({
    clientId: "YOUR-GOOGLE-CLIENT-ID"
});

var app = express();
app.use(googleTokenVerifier);

app.get('/', function (req, res) {
  // Get the e-mail from google (email OAuth scope)
  console.log('User e-mail: ', req.googleProfileInfo.email);
});

app.listen(8080);

// curl command that sends an HTTP request with a valid Google ID Token
// curl -H "x-googleid-token: {GOOGLE-ID-TOKEN-HERE}" http://127.0.0.1:8080

See more

Google Sign-In Authenticate with a backend server

MIT Licensed