Created
September 10, 2019 20:08
-
-
Save isuruhettiarachchi/9f77ae2cc18cc8cfe11cf007d5c96b1d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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