Authenticating with Access Token
Closed this issue ยท 8 comments
I believe that I'm having an issue with authentication. I'm trying to do some server side operations and I have a test environment setup with intercom. That test environment has an app ID and an access token for making API calls.
I'm not getting any exceptions but I've tried instantiating an Authentication object by using both constructors and fetching a list of my users is returning null (as well as fetching a known user by email):
var auth = new Authentication("mylonghexstringthatisactuallymyaccesstoken");
and
var auth = new Authentication("myappid", "mylonghexstringthatisactuallymyaccesstoken");
I tried some calls with a UsersClient object and I get null values for any call that I make. Here's some example code that I have:
UsersClient usersClient = new UsersClient(auth); User moi = usersClient.View(new User() { email = "jeff@mydomainthatiown.com" }); Users allUsers = usersClient.List();
Am I making these calls correctly? Or would this be some sort of bug? I tried the nodejs SDK and I can make calls to Intercom with no problem so I'm trying to find out where my issue lies.
Hey @jefflafay! ๐ That's an odd one. I tried that code on my end and it works correctly. Is it possible that you have a mistyped access token? They always end with a =
but it doesn't always get automatically selected when copy-pasting from our integrations page.
If that's not the case, could you tell me your app_id? Alternatively, if you don't feel comfortable sharing it here, you can always contact us at team@intercom.io and we can look into it. I think that going through our server logs to see what we are getting would be a good way to figure out exactly what's wrong. ๐
Hey @kmossco I double checked the access token and I'm utilizing the correct one. So a few questions for you..
Which Authentication constructor should I be using when making calls with the access token? I provided two examples but I would like to know which one is correct. Also, if it's an access token issue, shouldn't some type of exception be thrown when I make calls? That's what I expected and it was kind of strange to just get null values from the SDK calls instead.
Thanks!
Hey @jefflafay! The only accepted authenticator at the moment is this:
var auth = new Authentication("mylonghexstringthatisactuallymyaccesstoken");
The other one was reserved for when we were using API keys, and expects that you pass an API key there for it to work. I have however just tried the other method with app_id + access token and I get immediately an API exception:
{"type":"error.list","request_id":"b153f3p0f5n5nvkj5vug","errors":[{"code":"token_not_found","message":"Unauthorized"}]}
Are you not getting these exceptions? I checked our logs for your app_id and I was able to find that in your test app there were 2 calls that went through in the last 6 hours but they all failed with a 404:
[api_err][app_id][b152bou1e4th7okh1oi0][User Not Found][{"email"=>"jeff@emailused.io", "controller"=>"api/v3/users", "action"=>"show"}]
(email changed there for privacy reasons)
Are you sure that this user exists in your app? I also noticed that you are using your test app's access token, so is it possible that it is causing this confusion?
In any case, I confirmed that we are throwing exceptions correctly - so I'd also check your debugger settings just in case it is suppressing them. ๐
So I tried running as admin and making sure that debugger settings are fine. I also turned off windows firewall in case that was the issue. I added extra characters to the token and attempted a call but yielded the same results: no exception and null value.
The other calls that you saw were from a client that I wrote in the mean time to call the REST API to carry out operations. I deleted a user yesterday and wanted to see what kind of error that I would receive if I tried to retrieve them. I'm going to have to continue with making calls to the REST API instead in the mean time because the SDK isn't working for me and I'm not sure what else I could look at.
That's really odd. ๐ค Can you tell me what IDE if any you are using, what debugger and if the code you sent us before isn't the whole file, could you sanitise it and send it over so I can try on my end?
Sure, I'll just zip up the project and send it to you. What email can I send it to?
Can you reply to your thread in Intercom with Emily and attach the zip there? Currently based in Europe so won't be online for much longer, and this way she can forward it to me to test it first thing tomorrow. ๐
Closing this one as after talking with @jefflafay I could see that he is compiling the current version of the SDK with .NET Core, while we only support .NET 4.5. Testing locally I got a lot of debug messages from Visual Studio and the program didn't compile. This is not something we will be able to fix as we are hoping to release very soon our new version that supports .NET Standard 2.0.