davglass / doorbot

Ring.com Doorbell API
Other
317 stars 55 forks source link

Getting 401 when authenticating #8

Closed asantaga closed 7 years ago

asantaga commented 7 years ago

Hey all,

Ive finally found some time to tinker with the ring api, and implement something to download all ring videos, and I noticed that the API has been upgraded.. Alas Ive tried using it and for some reason I simply get a 401 when authenticating.. Any ideas? anyone else getting this error?

KoenZomers commented 7 years ago

Did you try using Fiddler in combination with the Windows 10 App of Ring? That will show you all the glory details of the API with ease. One thing I noticed when doing this is that there's a whole lot more in the body of the /session call POST where it authenticates than this code here provides. Perhaps that's why you're getting an error? Try POSTing the following stuff in your auth call:

device[metadata][device_model]=Test&device[metadata][device_name]=Test&device[metadata][resolution]=800x600&device[metadata][app_version]=1.3.810&device[metadata][app_instalation_date]=2017-08-11+22%3A16%3A45Z&device[metadata][manufacturer]=Test&device[metadata][device_type]=tablet&device[metadata][architecture]=x64&device[metadata][language]=en&device[os]=windows&device[hardware_id]=Test&device[app_brand]=ring

davglass commented 7 years ago

@asantaga Can I see an example of how you are using it? I have this in a Nagios script that runs 4 times an hour and I have no issues with the API.

@KoenZomers The doorbot sends all of that data, but from my tests those parameters aren't needed nor required to make the request. The only fields that were required were: device[os] and device[hardware_id]. All other fields could be dropped and it still authenticates perfectly fine.

asantaga commented 7 years ago

My code is trivial.. but its very strange..

it now appears to work "most" of the time.. very weird

const RingAPI = require('doorbot'); const ring = RingAPI({ email : 'xxxxxx@gmail.com', password : 'yyyyy' }); console.log(ring); ring.devices((e,devices) => { console.log(e,devices); });

oliverphardman commented 7 years ago

I'm getting a 401 while using @asantaga's code. Unsure as to why.

asantaga commented 7 years ago

its weird, it sometimes works...

oliverphardman commented 7 years ago

Hasn't worked once for me.

KoenZomers commented 7 years ago

@davglass, you're right on that. Tried it in the C# variant I have created and indeed with just those two the Ring service will also accept the request, so that can't be the issue here.

@starsky135, @asantaga, not sure if you guys are into C#, but you could give it a try using the code I've put online to see if that makes any difference. It shouldn't, but you never know: https://github.com/KoenZomers/RingApi. Otherwise I would recommend to run a Fiddler trace while executing the code to see what flies over the wire and what comes back.

oliverphardman commented 7 years ago

@KoenZomers Thanks for that, I am into C# so I'll give that a go.

KoenZomers commented 7 years ago

@starsky135, just grab a copy of my code, copy the App.sample.config of the UnitTest project to App.config, enter your Ring username and password and kick off the Unit Tests. That should give you insight in if it works. I don't have a single time myself where it fails.

jhurliman commented 7 years ago

Could this be due to the different API parameters being passed by JS and C# clients? See https://github.com/davglass/doorbot/blob/master/doorbot.js#L138-L142 vs https://github.com/KoenZomers/RingApi/blob/master/Api/Session.cs#L84-L95.

KoenZomers commented 7 years ago

@jhurliman, that's what we discussed above in this thread already. I tested it earlier today with just the two used by this JS version and that works as well, so it can't be that.

Sfinx commented 7 years ago

It is ring servers bugs. Just reconnect again ;)

asantaga commented 7 years ago

@KoenZomers sorry been on hols, Im not into C# alas :-( @Sfinx Not sure this is the ring servers, Ive been tinkering with a Python version of a RingAPI and it works fine...connects quickly.. so it must be a little bug....

proxy tracing time here we come!

Sfinx commented 7 years ago

I'm using my own c++ version - it is connecting every time too. the minimum three req fields are 'device[os]', 'device[hardware_id]' and api_version. But I'm definitely seeing some short cloud servers blackouts even using ring stock android app.

asantaga commented 7 years ago

Seams to work fine today... Im closing this off as it appears to work now.. probably a bug but these sorts of bugs are the hardest to find.... if it persists I'll reopen the issue

davglass commented 7 years ago

@asantaga You should update to the latest doorbot@3.0.1, I've fixed some issues around authentication and using the tokens..

asantaga commented 7 years ago

@davglass thanks :-)

asantaga commented 7 years ago

Confirmed fixed , works robustly now

mrose17 commented 7 years ago

+1