Dear Coda Pack Makers.
I have recently joined Pack Studio Beta with little knowledge of coding.
The first thing I tried was mimicking CRUD operation on Google Calendar events with my own pack.
But I just keep failing authorization.
I figured out that I must use OAuth2.0 for Google API’s authorization, and also Coda seems to have OAuth2.0 support, but I can’t make it work.
Things that I have done so far is listed bellow.
- Set up a project on Google Cloud Platform, created credentials, and got Client ID and Client Secret (But I may have made mistakes, so I am willing to start from scratch.)
If that is not too much of work, would any one of experienced coders like you help me get through this authorization phase?
This is the code I have now
import * as coda from "@codahq/packs-sdk";
export const pack = coda.newPack();
pack.setUserAuthentication({
type: coda.AuthenticationType.OAuth2,
authorizationUrl: "https://accounts.google.com/o/oauth2/v2/auth",
tokenUrl: "https://oauth2.googleapis.com/token",
scopes: [
"https://www.googleapis.com/auth/calendar",
"https://www.googleapis.com/auth/userinfo.email"
],
additionalParams: {
access_type: "offline",
prompt: "consent",
},
getConnectionName: async function(context) {
let response = await context.fetcher.fetch({
method: "GET",
url: "https://www.googleapis.com/auth/userinfo.email"
});
return response.body.email;
}
});
pack.addNetworkDomain("www.googleapis.com");
pack.addFormula({
name: "GetEmail",
description: "Get the gmail address of the user.",
isAction: true,
parameters: [],
resultType: coda.ValueType.String,
execute: async function ([], context) {
let response = await context.fetcher.fetch({
method: "GET",
url: "https://www.googleapis.com/auth/userinfo.email"
});
return response.body.email;
},
});
References that I am reading