My app seems to be throwing an error when trying to fetch from any external API. I have followed the tutorial here https://developer.atlassian.com/platform/forge/use-an-external-oauth-2.0-api-with-fetch/
I have the following function:
const myapi = await api.asUser().withProvider("gitlab", "gitlab-server")
if (!await myapi.asUser().withProvider("gitlab", "gitlab-server").hasCredentials()) {
await myapi.asUser().withProvider("gitlab", "gitlab-server").requestCredentials();
}
My manifest.yml looks like this:
permissions:
scopes:
- read:jira-work
external:
fetch:
backend:
- 'https://cd.mycompany.com'
providers:
auth:
- key: gitlab
name: Gitlab
scopes:
- 'profile'
- 'read_user'
type: oauth2
clientId: 123
remotes:
- gitlab-server
bearerMethod: authorization-header
actions:
authorization:
remote: gitlab-server
path: /oauth/authorize
exchange:
remote: gitlab-server
path: /oauth/token
revokeToken:
remote: gitlab-server
path: /oauth/token
retrieveProfile:
remote: gitlab-server
path: /oauth/userinfo
resolvers:
id: sub
displayName: email
however, I get the following error:
invocation: f79fe9594621785c index.run
ERROR 19:05:25.835 f79fe9594621785c myapi.asUser is not a function
TypeError: myapi.asUser is not a function
at fetchDetailsForMRs (webpack:///src/index.jsx:52)
at async fetchMRsForIssue (webpack:///src/index.jsx:18)
at async /tmp/tunnel8g1G0RaH6bsKV/index.js:14189:99
at async /tmp/tunnel8g1G0RaH6bsKV/index.js:14349:21
at async asyncMap (webpack:///node_modules/@forge/ui/out/reconcile.js:12)
at async /tmp/tunnel8g1G0RaH6bsKV/index.js:14301:29
at async asyncMap (webpack:///node_modules/@forge/ui/out/reconcile.js:12)
at async /tmp/tunnel8g1G0RaH6bsKV/index.js:14363:23
at async /tmp/tunnel8g1G0RaH6bsKV/index.js:14231:31
This appears to be identical to the code in the example…
If I replace the index code with this:
const myapi = await api.asUser().withProvider("gitlab", "gitlab-server")
if (!await api.asUser().withProvider("gitlab", "gitlab-server").hasCredentials()) {
await api.asUser().withProvider("gitlab", "gitlab-server").requestCredentials();
}
Then it takes me through the authentication process, but I just get an error stating could not retrieve access token from the provider
Any ideas on why it’s not working for me?