Can't use GitHub API with @forge/api's fetch

Hi. I’d like to use GitHub API on my forge(Jira) appliccation.

I’ve been using @forge/ui which is previous version (not UI Kit 2 which requires @forge/react) and there were no problem calling github api like this:

const res = await fetch(`https://api.github.com/app/installations/${this.installationId}/access_tokens`, {
    method: 'POST',
    headers: {
    Accept: 'application/vnd.github+json',
    Authorization: `Bearer ${this.authToken}`,
    'X-GitHub-Api-Version': '2022-11-28',
  }
})

and to request this, I had to create a sign to get this.authToken. So I’ve installed crypto package and used createSign function from it.

app:
  runtime:
    name: nodejs18.x

Also, I’ve been using nodejs18 version and this works fine.

But after I tried to migrate to UI Kit 2, I’ve replaced some component apis and did nothing to this crypto required features. But it fails with crypto, stream, buffer errors.

So I’ve tried to install crypto-browserify, stream-browserify, and buffer, crypto, stream which all failed.

How could I use this github api? Is there another way to do this with Oauth?

Hi @TonyPark - there is a built-in feaure in Forge called externalAuth that lets you integrate with remote OAuth providers. Details here: https://developer.atlassian.com/platform/forge/runtime-reference/external-fetch-api/

I’m not sure if it will work with the Github API, but perhaps worth a try as it would substantially reduce the amount of code you need to write?

3 Likes