karbassi / netatmo

A node.js module to hook into the netatmo API.
MIT License
57 stars 46 forks source link

Client credentials grant type deprecated #81

Open arenddeboer opened 1 year ago

arenddeboer commented 1 year ago

" Authenticate error: unauthorized_client" It looks like Netatmo has finaly disabled "Client credentials grant type" which was slated for October 2022. (https://dev.netatmo.com/apidocumentation/oauth)

One can generate an app with tokens on the netatmo dev site: https://dev.netatmo.com/apps/createanapp and I made a dirty fork to use this refresh token to request a new authorization_token: https://github.com/arenddeboer/netatmo/blob/main/netatmo.js

I do wonder how long the refresh token generated on the netatmo dev site is valid, so this solution may not be workable if it expires.

runbert commented 1 year ago

Hi! Today I got the " unauthorized_client" error when running my NodeJS app. I tried the code from the fork above and the "unauthorized client" error got away, but I don't understand how to use the API now when a refresh token should be used instead? How do I get the refresh token? Should I provide it in the auth object? I would be really thankful if someone can provide an example of how the auth object should look to work with the new code from the fork, for i.e:

var netatmo = require('netatmo'); var auth = { "client_id": "testtest", "client_secret": "Test123123", "username": "test@hotmail.com", "password": "test123", "refresh_token": "token123" }; var api = new netatmo(auth);

Thanks alot!

arenddeboer commented 1 year ago

This is how I call it:

const api = new Netatmo({
  client_id: 'clientId',
  client_secret:'clientSecret',
  scope: 'read_station',
  refresh_token: 'refreshToken',
})

It's probably the scope that is missing. I only use read_station, so adjust this as needed.

arenddeboer commented 1 year ago

Looking into it a bit, the fork skips the authenticate function in favor of authenticate_refresh. authenticate() does some variable initialization like:

scope = args.scope || 'read_station read_thermostat write_thermostat read_camera write_camera access_camera read_presence access_presence read_smokedetector read_homecoach';
runbert commented 1 year ago

Thanks alot for your quick answer!

It worked!

One of the main issues were that I needed to login to https://dev.netatmo.com/apps/ for the specific app and then use their token generator and generate a Refresh Token. Had a little hard time finding that out...

Thanks again!

arenddeboer commented 1 year ago

Sorry I totally overlooked your refresh token question. Glad you got it working.