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
const redirectPath = '/auth/google/callback';
const creds = {
"clientId": "CLIENT_ID",
"clientSecret": "CLIENT_SECRET",
"redirectUri": `http://example.com${redirectPath}`
};
const googleOAuth = require('google-oauth-middleware')(creds,
async (credentials, profile, next) => {
GoogleAccount
.addAsync(credentials, profile)
.then(() => next(), next);
}
);
app.get('/addGoogleAccount', googleOAuth.authenticate({
scope: [
'profile',
'email',
'openid',
]
}));
app.get(redirectPath,
googleOAuth.authenticate(),
(req, res, next) => {
},
(err, req, res, next) => {
}
);