我正在使用这个npm库 - https://www.npmjs.com/package/googleapis,我使用以下Express路线/user/:
/* Redirect to the google login page */
router.get('/login', function (req, res) {
res.redirect(auth.generateUrl());
});
/* The callback from the google OAuth API call */
router.get('/callback', function (req, res) {
auth.authenticate(req.query.code);
res.send();
});
Run Code Online (Sandbox Code Playgroud)
auth是这个模块:
var oAuth2 = require('googleapis').auth.OAuth2;
var oauth2Client = new oAuth2([CLIENT_ID], [CLIENT_SECRET], [DOMAIN] + '/user/callback');
module.exports = {
/**
* Generate a url to redirect to for authenticating via Google
*
* @return {String}
*/
generateUrl: function () {
return oauth2Client.generateAuthUrl({
access_type: …Run Code Online (Sandbox Code Playgroud)