Last active
May 14, 2019 11:32
-
-
Save Salamit/4fd3a669bda18f50f0c31691a86ffe45 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import '../modules/index.js'; | |
import { Meteor } from 'meteor/meteor'; | |
const {google} = require('googleapis'); | |
const fs = require('fs'); | |
Meteor.startup( function (){ | |
Meteor.methods({ | |
//credits: https://morioh.com/p/1313d7785668/node-js-using-google-sheets-api-with-oauth-2 | |
//credits: http://www.gethugames.in/2012/04/authentication-and-authorization-for-google-apis-in-javascript-popup-window-tutorial.html | |
//authenticate the app to get access to user's google drive sheets | |
'googleAuth'(){ | |
const path = process.env.PWD + '/credentials.json'; | |
const credentials = JSON.parse(fs.readFileSync(path, 'utf-8')); | |
const { | |
client_secret: clientSecret, | |
client_id: clientId, | |
redirect_uris: redirectUris, | |
} = credentials.web; | |
const oauth2Client = new google.auth.OAuth2( | |
clientId, clientSecret, redirectUris[0], | |
); | |
// generate a url that asks permissions for Blogger and Google Calendar scopes | |
const scopes = [ | |
'https://www.googleapis.com/auth/spreadsheets' | |
]; | |
const url = oauth2Client.generateAuthUrl({ | |
// 'online' (default) or 'offline' (gets refresh_token) | |
access_type: 'offline', | |
// If you only need one scope you can pass it as a string | |
scope: scopes | |
}); | |
try { | |
return url | |
} catch(exception){ | |
} | |
return url; | |
} | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment