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

Quick Fix for #167 #168

Merged
merged 1 commit into from
Jul 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/Netatmo/Client.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Threading.Tasks;
using System;
using System.Threading.Tasks;
using NodaTime;

namespace Netatmo
Expand All @@ -20,12 +21,18 @@ public Client(IClock clock, string baseUrl, string clientId, string clientSecret

public Task GenerateToken(string username, string password, Scope[] scopes = null)
{
Console.WriteLine("Client credentials grant type is deprecated since october 2022 and will not work!");
return CredentialManager.GenerateToken(username, password, scopes);
Riges marked this conversation as resolved.
Show resolved Hide resolved
}

public void ProvideOAuth2Token(string oauth2Token)
public void ProvideOAuth2Token(string accessToken)
{
CredentialManager.ProvideOAuth2Token(oauth2Token);
CredentialManager.ProvideOAuth2Token(accessToken);
}

public void ProvideOAuth2Token(string accessToken, string refreshToken)
{
CredentialManager.ProvideOAuth2Token(accessToken, refreshToken);
}

public Task RefreshToken()
Expand Down
13 changes: 9 additions & 4 deletions src/Netatmo/CredentialManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,24 @@ public async Task GenerateToken(string username, string password, Scope[] scopes

CredentialToken = new CredentialToken(token, clock);
}

public void ProvideOAuth2Token(string oauth2Token)
public void ProvideOAuth2Token(string accessToken, string refreshToken)
{
var appToken = new Token()
{
AccessToken = oauth2Token,
RefreshToken = null,
AccessToken = accessToken,
RefreshToken = refreshToken,
ExpiresIn = 20
};

CredentialToken = new CredentialToken(appToken, clock);
}

public void ProvideOAuth2Token(string accessToken)
{
ProvideOAuth2Token(accessToken, null);
}

public async Task RefreshToken()
{
// TODO : Handle not success status codes (rate limit exceeded, api down, ect)
Expand Down
2 changes: 1 addition & 1 deletion src/Netatmo/IClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public interface IClient
IAirClient Air { get; }
ICredentialManager CredentialManager { get; }
Task GenerateToken(string username, string password, Scope[] scopes = null);
void ProvideOAuth2Token(string oauth2Token);
void ProvideOAuth2Token(string accessToken);
Task RefreshToken();
}
}
3 changes: 2 additions & 1 deletion src/Netatmo/ICredentialManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ public interface ICredentialManager
CredentialToken CredentialToken { get; }
string AccessToken { get; }
Task GenerateToken(string username, string password, Scope[] scopes = null);
void ProvideOAuth2Token(string oauth2Token);
void ProvideOAuth2Token(string accessToken);
void ProvideOAuth2Token(string accessToken, string refreshToken);
Task RefreshToken();
}
}
Loading