Skip to content

Instantly share code, notes, and snippets.

@isuruhettiarachchi
Created September 10, 2019 20:08
Show Gist options
  • Save isuruhettiarachchi/9f77ae2cc18cc8cfe11cf007d5c96b1d to your computer and use it in GitHub Desktop.
Save isuruhettiarachchi/9f77ae2cc18cc8cfe11cf007d5c96b1d to your computer and use it in GitHub Desktop.
const { google } = require('googleapis');
require('dotenv').config()
// google app config
const googleConfig = {
clientId: process.env.GOOGLE_CLIENT_ID,
clientSecret: process.env.GOOGLE_CLIENT_SECRET,
redirect: 'http://localhost:3000/auth/success'
}
// scopes use for the application
const defaultScope = [
'https://www.googleapis.com/auth/calendar.events.readonly',
'profile',
'email'
]
// oauth2 client
function createConnection() {
return new google.auth.OAuth2(
googleConfig.clientId,
googleConfig.clientSecret,
googleConfig.redirect
);
}
// generate authentication url
function getConnectionUrl(auth) {
return auth.generateAuthUrl({
access_type: 'offline',
prompt: 'consent',
scope: defaultScope
});
}
// get auth url
module.exports.urlGoogle = function () {
const auth = createConnection();
const url = getConnectionUrl(auth);
return url;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment