It took me a bit effort to understand google api example of oauth and how to apply to your webpage with Expressjs. if you are nodejs guru, this article is probably not for you. But if you find the original example provided by google is not straight forward, read on.
(here is original google api of oauth example)
(here is link to gist on github)
//this file is goauth2.js in your express routes folder //in app.js sources it and use it with route /auth/google //so the callback url could be naturally /auth/google/callback //this way the callback login can be in the same code file. var express = require('express'); var router = express.Router(); var google = require('googleapis'); var OAuth2Client = google.auth.OAuth2; var plus = google.plus('v1'); // Client ID and client secret are available at // https://code.google.com/apis/console var CLIENT_ID = YOUR_CLIENT_ID_HERE; var CLIENT_SECRET = YOUR_CLIENT_SECRET_HERE; var REDIRECT_URL = "http://localhost:3000/auth/google/callback"; var oauth2Client = new OAuth2Client(CLIENT_ID, CLIENT_SECRET, REDIRECT_URL); //use browser visit http://localhost:3000/auth/google router.get('/', function(req, res){ var url = oauth2Client.generateAuthUrl({ access_type: 'offline', // will return a refresh token scope: 'https://www.googleapis.com/auth/plus.login' }); //trigger redirect to google login page, which will eventually callback to // http://localhost:3000/auth/google/callback res.redirect(url); }); //after login successful, the route will be called //callback url contains code query to be used to get token for further //google plus query. router.get('/callback', function (req, res) { oauth2Client.getToken(req.query.code, function (err, tokens) { if (err) { return callback(err); } //the callback functions contains tokens for oauth2client to set and for //next round of query in google plus. oauth2Client.setCredentials(tokens); //finally us plus api to query authenticated user profile plus.people.get({ userId: 'me', auth: oauth2Client }, function (err, profile) { if (err) { console.log('An error occured', err); }else { //do stuff with user profile console.log(profile); } //redirect back to whichever page after user login. res.redirect("/"); }); }); }); module.exports = router;