Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Netatmo has changed token request-code no longer works #167

Open
MurphyLuth opened this issue Jul 15, 2023 · 9 comments
Open

Netatmo has changed token request-code no longer works #167

MurphyLuth opened this issue Jul 15, 2023 · 9 comments

Comments

@MurphyLuth
Copy link

This code has been working great until 7/13/2023 when it appears Netatmo has changed the way to request a token.

It looks like they switched to Oauth2 (see https://dev.netatmo.com/apidocumentation/oauth).

Authorization is needed before a token can be requested.

@TheAxelander
Copy link
Contributor

My current workaround is instead of using client.GenerateToken() I generate a token on dev.netatmo.com and then provide then new Access Token in my code via client.ProvideOAuth2Token()

Of course this is no full automation and would need to be fixed here. But at least my scripts now work again...

@TheAxelander
Copy link
Contributor

My hope was now to initially generate Access Token and Refresh Token, modify the coding here to be able to pass the Refresh Token in methods like CredentialManager.ProvideOAuth2Token(string oauth2Token) and CredentialManager.RefreshToken() to be able to always request a new Token via Refreshing a token API call in Netatmo, but for some reason this just doesn't work if I test this in Postman.

No idea if I do something wrong or if there are additional changes that are not documented yet on Netatmo side.

image

@MurphyLuth
Copy link
Author

Did you look at the link
https://dev.netatmo.com/apidocumentation/oauth
They show the first post as:
https://api.netatmo.com/oauth2/authorize?
client_id=[YOUR_APP_ID]
&redirect_uri=[YOUR_REDIRECT_URI]
&scope=[SCOPE_SPACE_SEPARATED]
&state=[SOME_ARBITRARY_BUT_UNIQUE_STRING

I think this has to be done before you can even request a token.

@TheAxelander
Copy link
Contributor

I have a valid Access and Refresh token (I was also able to get data with that token). It was generated on the My Apps Page

@MurphyLuth
Copy link
Author

I used your temporary fix with the tokens from My Apps Page. Works for now. Thanks for your help.

@TheAxelander
Copy link
Contributor

You're welcome. But this token needs to be renewed at some point in time (I think it was working for ~3 hours on my side). And this token refreshment was not yet working for me for some reason...

@TheAxelander
Copy link
Contributor

I have created a PR #168 with a quick fix for this issue

@Riges
Copy link
Owner

Riges commented Jul 19, 2023

I think I need a rewrite of this library for better handler Netatmo API's and use new C# features...

Riges pushed a commit that referenced this issue Jul 19, 2023
Extend CredentialManager to accept refresh_token and add warning message
for deprecated GenerateToken

Example usage:

```csharp
var clientId = "myClientId";
var clientSecret = "myClientSecret";
var accessToken = "myAccessToken";
var refreshToken = "myRefreshToken";

var client = new Client(
    SystemClock.Instance, "https://api.netatmo.com/",
    clientId,
    clientSecret);

client.ProvideOAuth2Token(accessToken, refreshToken);
await client.RefreshToken();
var stationsData = await client.Weather.GetStationsData();
```

Refs: #167 #168
@Riges
Copy link
Owner

Riges commented Jul 19, 2023

1.5.3 published on Nuget

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants