-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathAuthenticator.cs
31 lines (28 loc) · 923 Bytes
/
Authenticator.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
namespace BoardGameGeek.Dungeon;
public sealed class Authenticator
{
public Authenticator(ILogger<Authenticator> logger, IBggService bggService)
{
Logger = logger;
BggService = bggService;
}
public async Task AuthenticateUser(string userName, string? password)
{
var fileName = $"BGG-{userName}-Auth.txt"; // auth cache
if (password != null)
{
Logger.LogInformation("Authenticating user");
var cookies = await BggService.LoginUserAsync(userName, password);
await using var writer = File.CreateText(fileName);
cookies.WriteTo(writer);
}
else
{
var reader = File.OpenText(fileName);
var cookies = CookieJar.LoadFrom(reader);
BggService.LoginUser(cookies);
}
}
private ILogger Logger { get; }
private IBggService BggService { get; }
}