Skip to content

Commit fd06854

Browse files
committed
Refactor authorization and client identification
Modified `Program.cs` to always reauthorize the client by setting `reauth: true` in the `AuthorizeAsync` method call. Changed the reauthorization condition to check for client verification instead of an empty token. Removed the `Token` property from the `Secrets` class in `Secrets.cs`. Added a `UniqueId` property to the `BlinkClient` class in `BlinkClient.cs` to generate unique identifiers for each client instance, replacing the hardcoded `_uniqueId` value.
1 parent 133d4d5 commit fd06854

File tree

3 files changed

+9
-10
lines changed

3 files changed

+9
-10
lines changed

Sources/Blink.ConsoleTest/Program.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,12 @@ private static async Task Start()
1414
string json = File.ReadAllText("secrets.json");
1515
var secrets = JsonSerializer.Deserialize<Secrets>(json)!;
1616
BlinkClient client = new();
17-
var authData = await client.AuthorizeAsync(secrets.Email, secrets.Password, reauth: string.IsNullOrEmpty(secrets.Token));
17+
var authData = await client.AuthorizeAsync(secrets.Email, secrets.Password, reauth: true);
1818

19-
if (string.IsNullOrEmpty(secrets.Token))
19+
if (authData.Account.IsClientVerificationRequired)
2020
{
2121
string code = Console.ReadLine() ?? throw new Exception("No code entered");
2222
await client.VerifyPinAsync(code);
23-
24-
// Just save the authorization data and use it later to authorize.
2523
Console.WriteLine("Auth data: " + authData.ToJson());
2624
}
2725

Sources/Blink.ConsoleTest/Secrets.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,5 @@ public class Secrets
99

1010
[JsonPropertyName("password")]
1111
public string Password { get; set; } = string.Empty;
12-
13-
[JsonPropertyName("token")]
14-
public string Token { get; set; } = string.Empty;
1512
}
1613
}

Sources/Blink/BlinkClient.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
using System.Net.Http.Json;
88
using System.Threading.Tasks;
99
using System.Collections.Generic;
10-
using System.Net.Mime;
1110

1211
namespace Blink
1312
{
@@ -16,6 +15,11 @@ namespace Blink
1615
/// </summary>
1716
public class BlinkClient : IBlinkClient
1817
{
18+
/// <summary>
19+
/// Unique ID to avoid reauthorization by pin code
20+
/// </summary>
21+
public string UniqueId { get; set; } = Guid.NewGuid().ToString();
22+
1923
/// <summary>
2024
/// For some reason, their server returns empty response without this delay.
2125
/// You can control this delay by setting this property.
@@ -26,7 +30,7 @@ public class BlinkClient : IBlinkClient
2630
private int? _clientId;
2731
private int? _accountId;
2832
private HttpClient? _http;
29-
private readonly string _uniqueId = "15c204d5-1577-4825-9bc8-b09efe619f00";
33+
3034

3135
/// <summary>
3236
/// Authorize with email and password provided in constructor.
@@ -49,7 +53,7 @@ public async Task<LoginResult> AuthorizeAsync(string email, string password, boo
4953
string clientName = Assembly.GetEntryAssembly()!.GetName().Name + "_v" + Assembly.GetEntryAssembly()!.GetName().Version;
5054
var body = new
5155
{
52-
unique_id = _uniqueId,
56+
unique_id = UniqueId,
5357
email,
5458
password,
5559
client_name = clientName,

0 commit comments

Comments
 (0)