Using Meteor Google Auth with Google Drive API - javascript

I'm trying to use Meteor Google Auth with Google Drive API but meteor auth give only an access token, and Google Drive need a lots of other information (https://developers.google.com/drive/web/quickstart/quickstart-nodejs like clientID, clientSecret, ...).
It's possible to send directly the access token into this function ?
var drive = google.drive({ version: 'v2', auth: auth });
Thank's a lot!

Looking at that demo I would use settings by running meteor --settings client_secret.json and then inside your code:
authorize(Meteor.settings.web, listFiles);

Related

How can I get Google drive API to authenticate?

I am struggling a lot to get my authentication to work for Google drive api.
This is my current code.
const drive = google.drive({
version: 'v3',
auth: new google.auth.GoogleAuth({
keyFile: 'google-cloud-credentials.json',
scopes: ['https://www.googleapis.com/auth/drive.file'],
}),
});
No matter what I try, I get the error "ENOENT: no such file or directory, open '/var/task/google-cloud-credentials.json'"
I've also tried the following:
keyFile: path.resolve(__dirname, 'google-cloud-credentials.json'),
keyFile: './google-cloud-credentials.json',
keyFile: '../google-cloud-credentials.json',
keyFile: '../../google-cloud-credentials.json',
I should mention that I'm also deploying with with Serverless but in the past I've been able to get this to work.
So I found in the type definition for GoogleAuth that you can simply use credentials which takes the body of the credentials rather than keyFile which takes the path.
After that I just simply had to import JSON into my file and add it there.
that's not how you Auth. that's just creating google Auth object. you must fill it with credentials or it will do nothing.
maybe read the readme again. there's a standard implementation of oauth there. also feel free to ask a follow up

Passport.JS to get Google Calendar

I am currently trying to build a Calendar app in Node.JS hooked with Google Calendar. However, I have been struggling with trying to get a Calendar from the Google API. I have downloaded the GoogleApis npm package to assist PassportJS, but I can not seem to get passport to interact with GoogleAPIs. I was trying to find a method of using the already authenticated user to get a Calendar, but google has yielded no results. Is there a way to use Passport.JS to get a Google Calendar, or do I need to abandon PassportJS for this task entirely?
Here is the express route I am currently using to attempt to get a Calendar.
let auth = passport.authenticate('google', {
scope: ['profile', 'email',
'https://www.googleapis.com/auth/calendar.events',
'https://www.googleapis.com/auth/calendar.readonly']
})
/*
I want to know if there is a way to Get The Calendar without the Code below or if I can use Passportjs for the Credentials Section
*/
const client = google.auth.getClient({
credentials: credentials
scopes: ['https://www.googleapis.com/auth/calendar'],
})
calendar.events.list({
calendarId: 'CALID',
...

How to get a cognito users' group (in AWS JS SDK V3)

I try to migrate from AWS JavbaScript SDK V2 to V3.
I want to retrieve the user groups a logged-in Cognito user (form an identity pool) belongs to.
In V2, this was as easy as looking in the ["accessToken"].payload['cognito:groups'] element of the sign-in response.
In V3 it's not part of the response. How do I get this piece of information in V3?
I am using Amplify Auth, so I use the following code:
const session = await Auth.currentSession();
let idToken = session.getIdToken();
console.log(idToken.payload["cognito:groups"]);
You should just switch to "idToken" instead of "accessToken" in the sign-in response, and that should do the trick.

Access to Google analytic management API

I wish to use Google analytic management API and I have very basic problem that I am struggling with. For both Javascript and Python that I tried this instruction, it says there is no module named 'analytics'. Do I need to use some codes to connect to my Google analytic account?
function listFilters() {
var request = gapi.client.analytics.management.filters.list({
'accountId': '123456'
});
request.execute(printFilters);
}
Would you please help me to know what I'm missing?
It mentions here that you need to have analytics object authorized which is why you're getting no analytics module error
http://take.ms/Gk7z6
Here's how you can get your analytics authorized object
https://developers.google.com/analytics/devguides/config/mgmt/v3/mgmtReference/management/filters/list#auth
https://developers.google.com/analytics/devguides/config/mgmt/v3/authorization
Here's how you can get started with the javascript api library
https://developers.google.com/api-client-library/javascript/start/start-js

How to connect to Google Drive and create Google Docs with meteor?

My web app uses Meteor.loginWithGoogle with requestPermissions: ['email'] to login users.
I would like to connect to Google Drive of some users on their request and create some Google Docs.
1. Getting permission
How can I get the permission to access the Google Drive of the user?
Should I call the function Meteor.loginWithGoogle with more permissions? Maybe with something like :
requestPermissions: ['email https://www.googleapis.com/auth/drive.file'] ?
Should I do this every time I want to access the Google Drive of the user ?
2. Listing Google Docs and creating new
How can I list and create new Google Docs?
Thanks a lot for your help !
1/ Separate permissions with Strings like this:
Meteor.loginWithGoogle({
forceApprovalPrompt: true,
requestOfflineToken: true,
requestPermissions: ['email', 'https://www.googleapis.com/auth/drive.file']);
Use requestOfflineToken to be able to access it even if the user is not connected.
2/ Use the Google api. with a HTTP.call() or use a package like https://github.com/percolatestudio/meteor-google-api

Categories