homebridge-plugins / node-arlo

JS library for Arlo Cameras
17 stars 15 forks source link

Beta Branch type-rest-client default PersonalAccessTokenCredentialHandler not compatible with Arlo API #24

Closed mrbythatmuch closed 4 years ago

mrbythatmuch commented 4 years ago

Not sure if I'm posting this correctly didn't see how to associate it with the Beta which issues are expected.... Problem / Bug overall is not able to receive event notifications. I will post a support request with my code looking for advice as I may not interacting with node-arlo correctly however by inspection I found a few issues the below being one

In the Beta branch client.js uses the default PersonalAccessTokenCredentialHandler implementation { PersonalAccessTokenCredentialHandler } from 'typed-rest-client/Handlers'; Arlo is expecting the the raw token returned from the login. The PersonalAccessTokenCredentialHandler implements prepareRequest as:

prepareRequest(options) { options.headers['Authorization'] =Basic ${Buffer.from(PAT:${this.token}).toString('base64')}; options.headers['X-TFS-FedAuthRedirect'] = 'Suppress'; }

Arlo API is not expecting the token to have 'Basic ' as a prefix nor have it be base64 encoded. The work around I choose to allow me to try and get further with being able to receive notification was to override the prepareRequest function after in the client constructor adding the line this.handler.prepareRequest = function (options) { options.headers['Authorization'] = this.token; options.headers['X-TFS-FedAuthRedirect'] = 'Suppress'; }.bind(this.handler); client.js in Beta branch with above override of prepareRequest

` constructor(userAgent = 'node-arlo', baseUrl = 'https://arlo.netgear.com/hmsweb') { this.userAgent = userAgent; this.baseUrl = baseUrl; /**

github-actions[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.