Hoping someone can help me here - Possibly the unstoppable @Eric_Koleda.
The Goal: is simply to continue learning more about creating Coda Packs and increase knowledge of Javascript. Im an avid athlete and hoping to make a Strava pack.
The Problem: Authentication - I just can’t wrap my head around authentication. Can someone help me out in terms of writing the correct code to allow authentication to Strava for a Coda pack?
Heres some resources that I’ve been looking through:
More specifically, Im confused about these few things:
In order to generate a client_id I need to first create an application with an authorization callback domain - for the life of me I can’t figure out what that means? (see screenshot below)
Apparently I also need a Client Secret? Hmmmmmm. . .
Thanks for any help you can give! My goal is to make a sync table to bring in all the activities by an athlete. I know that if I can just get past this whole authorization thing I can make it the rest of the way
In the docs I shared you can see the step by step to add your client_id and client_secret (which Strava will provide after you create the App filling authorization callback).
@Scott_Collier-Weir - I love how you keep pushing yourself to learn new skills, keep at it! Figuring out how to map an API’s authorization documentation to a Pack is a bit of an art, but the more times you do it the easier it will get. @Leandro_Zubrezki has put you on the right track, let us know how it goes. As to the fields that you have to supply in the API console, each API does it a little differently and requires different things. Usually the “website” field isn’t technical, it just shows up on the approval screen.
Just to double-check, have you entered your client ID and client secret into the Settings tab of the Pack Studio editor? I still regularly forget that step, so thought I’d ask.
This error indicates that the redirect URL you configured in their console doesn’t match the one that Coda is using. The value should be https://coda.io/packsAuth/oauth2, which is listed in the docs and the OAuth2 dialog itself.
You will need to configure the pack authorization to add an additional query param, redirect_uri: https://coda.io/packsAuth/oauth2in additionalParams.
You need to define the scope you want, take a look at Strava Developers for the options, this is important because if not setup correctly your request won’t work.
Maybe because the scopes there are off? Under access token and refresh token it has the scopes as read. . . But for the life of me I can’t figure out how to change them
I just did some testing myself and got Strava OAuth2 working. That error message definitely seems related to having an incorrect domain in the “Authorization Callback Domain” field.
import * as coda from "@codahq/packs-sdk";
export const pack = coda.newPack();
pack.setUserAuthentication({
type: coda.AuthenticationType.OAuth2,
authorizationUrl: "https://www.strava.com/oauth/authorize",
tokenUrl: "https://www.strava.com/oauth/token",
scopes: ["read"],
getConnectionName: async function(context) {
let response = await context.fetcher.fetch({
method: "GET",
url: "https://www.strava.com/api/v3/athlete",
});
let user = response.body;
return user.username;
},
});
pack.addNetworkDomain("strava.com");