Access OAuth2 token

I’m attempting to build a pack for Linear.app, and as part of that I’d love to be able to use the Linear SDK in my Pack (I’m developing locally) rather than having to translate all the graphql queries to strings.

However, in order to do that, I need to provide the LinearClient with the OAuth2 token that Coda is getting for me using pack.setUserAuthentication.

Is there a way to access and consume that token once Coda gets it from the user? Ideally, I’d want to do something like:

pack.setUserAuthentication({
  type: coda.AuthenticationType.OAuth2,
  authorizationUrl: "https://linear.app/oauth/authorize",
  tokenUrl: "https://api.linear.app/oauth/token",
  scopes: ["read", "write"],
  getConnectionName: async function (context) {
    let response = await context.fetcher.fetch({
      method: "POST",
      url: "https://api.linear.app/graphql",
      body: JSON.stringify({ "query": `{ query Me { viewer { id name email } }`})
    })

    return response.body?.data.viewer.name
  }
});

// Authenticated Linear Client
const client = new LinearClient({
  accessToken: pack.AUTH_TOKEN
})
1 Like

Hi @Nick_Cannariato - Unfortunately for security reasons we don’t allow Pack authors to get direct access to the access token. The Packs runtime will automatically add the access token onto the HTTP request, which is a bit of a different paradigm than most SDKs.

Additionally, I don’t think their SDK would work out of the box. All Packs HTTP requests need to go through the custom context.fetcher.fetch interface, which I’d be surprised their SDK supports. You could in theory clone their SDK and patch it to use Coda’s fetcher, and in that case you could also remove the need to pass in the access token too.