Skip to content

Commit 9ae527b

Browse files
committed
Simplifies authentication flow.
Refactors the authentication flow to streamline error handling. Removes the `OneOf` return type and dedicated error records for wrong credentials and captcha requirements, returning null instead to indicate failure. This change simplifies the calling code by allowing it to directly check for a null session, instead of having to handle different error types.
1 parent cb86bb1 commit 9ae527b

2 files changed

Lines changed: 5 additions & 11 deletions

File tree

src/GameforgeConnector/GameforgeClient.cs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@
77

88
namespace GameforgeConnector;
99

10-
11-
public record WrongCredentials;
12-
public record Captcha(string ChallengeId);
13-
1410
public record GameforgeClientSettings(
1511
string InstallationId,
1612
string ChromeVersion,
@@ -26,7 +22,7 @@ public class GameforgeClient(GameforgeClientSettings settings)
2622
AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate | DecompressionMethods.Brotli,
2723
});
2824

29-
public async Task<OneOf<GameforgeClientSession, WrongCredentials, Captcha>> ConnectAsync(string email, string password)
25+
public async Task<GameforgeClientSession?> ConnectAsync(string email, string password)
3026
{
3127
var fp = await settings.Fingerprint.CopyAndRefresh();
3228

@@ -55,8 +51,6 @@ public async Task<OneOf<GameforgeClientSession, WrongCredentials, Captcha>> Conn
5551

5652
return response.StatusCode switch
5753
{
58-
HttpStatusCode.Conflict => new Captcha(ParseChallengeId(response)),
59-
HttpStatusCode.Forbidden => new WrongCredentials(),
6054
HttpStatusCode.Created => new GameforgeClientSession(settings, ExtractToken(body)),
6155
_ => throw new InvalidOperationException($"Unexpected response {(int)response.StatusCode} {response.ReasonPhrase}: {body}")
6256
};

src/GameforgeConnector/GameforgeClientSession.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,10 @@ public async Task<List<GameAccount>> GetAccountsAsync()
6767
return accounts;
6868
}
6969

70-
public async Task<OneOf<GameTokenCreated, GameTokenCreationError>> GetGameTokenAsync(GameAccount account)
70+
public async Task<string?> GetTokenAsync(GameAccount account)
7171
{
7272
if (!await SendIovation(account.Id))
73-
return new GameTokenCreationError("Failed to send iovation request");
73+
return null;
7474

7575
var id = Guid.NewGuid() + "-" + new Random().Next(1000, 9999);
7676

@@ -108,12 +108,12 @@ public async Task<OneOf<GameTokenCreated, GameTokenCreationError>> GetGameTokenA
108108
var body = await response.Content.ReadAsStringAsync();
109109

110110
if (response.StatusCode != HttpStatusCode.Created)
111-
return new GameTokenCreationError($"Failed to get game token: {(int)response.StatusCode} {response.ReasonPhrase}");
111+
return null;
112112

113113
var json = JObject.Parse(body);
114114
var code = json["code"]?.ToString();
115115

116-
return new GameTokenCreated(code!);
116+
return code!;
117117
}
118118

119119
private string GenerateThirdTypeUserAgent(string accountId)

0 commit comments

Comments
 (0)