intercom / intercom-node

Node.js bindings for the Intercom API
https://developers.intercom.com
Other
366 stars 116 forks source link

apiKeyAuth returning "unauthorised" #329

Open poppet-uk opened 1 year ago

poppet-uk commented 1 year ago

Please use the following template to submit your issue. Following this template will allow us to quickly investigate and help you with your issue. Please be aware that issues which do not conform to this template may be closed.

For feature requests please contact us at team@intercom.io

Version info

Expected behavior

Screenshot 2022-11-14 at 23 48 05 Creating a new instance of the intercom Client using the "apiKeyAuth" should authenticate. "tokenAuth" works fine.

Actual behavior

Any request I make using the "apiKeyAuth" returns "unauthorized".

Steps to reproduce

  1. create a new Client providing the apiKeyAuth params.
  2. try to make a request to intercom

Logs

Error: Unauthorized
    at new BadResponseError (/Users/drakemacbook2/Documents/Programming/cc/node_modules/lib/errors/badResponse.error.ts:10:9)
    at Client.checkOnErrorInResponse (/Users/drakemacbook2/Documents/Programming/cc/node_modules/lib/client.ts:258:16)
    at Client.<anonymous> (/Users/drakemacbook2/Documents/Programming/cc/node_modules/lib/client.ts:204:24)
    at step (/Users/drakemacbook2/Documents/Programming/cc/node_modules/intercom-client/dist/client.js:52:23)
    at Object.throw (/Users/drakemacbook2/Documents/Programming/cc/node_modules/intercom-client/dist/client.js:33:53)
    at rejected (/Users/drakemacbook2/Documents/Programming/cc/node_modules/intercom-client/dist/client.js:25:65)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
SeanHealy33 commented 1 year ago

Hi @poppet-uk

I'm a little unsure of the issue here. The documented way of adding an api key is const client = new Client({ tokenAuth: { token: 'my_token' } }); as documented in the readme.

Could you let me know a little bit more about your use case

poppet-uk commented 1 year ago

Certainly,

So in the client.d.ts file, the types indicate that I can authenticate using an apiKey and appId.

Screenshot 2022-12-15 at 22 25 50

However trying to do so returns the aforementioned error.

Our usecase is that we have an intercom for production and an intercom app for testing. In order to work with exclusively our testing app, we can't simply authenticate with the authToken as I believe that's linked to our production env.

SeanHealy33 commented 1 year ago

So I did some digging on this.

appAPIKey in this context refers to a legacy token system we used before the Developer Hub was created (circa 2018).

If you created your app in the dev hub and have a auth key from there then it uses TokenAuth exclusively. The api is returning
unauthorized since your key does not exist on that workspace in the legacy auth system we have.

I'll keep this issue open though since we clearly need to document the different schemes of auth that the SDK supports and how they work.