feat: misskey auth

This commit is contained in:
sam 2024-12-12 16:44:01 +01:00
parent 51e335f090
commit 77c3047b1e
Signed by: sam
GPG key ID: B4EF20DDE721CAA1
6 changed files with 214 additions and 16 deletions

View file

@ -91,6 +91,34 @@ public static class KeyCacheExtensions
string state,
CancellationToken ct = default
) => await keyCacheService.GetKeyAsync<AddExtraAccountState>($"add_account:{state}", true, ct);
public static async Task<string> GenerateForgotPasswordStateAsync(
this KeyCacheService keyCacheService,
string email,
Snowflake userId,
CancellationToken ct = default
)
{
string state = AuthUtils.RandomToken();
await keyCacheService.SetKeyAsync(
$"forgot_password:{state}",
new ForgotPasswordState(email, userId),
Duration.FromHours(1),
ct
);
return state;
}
public static async Task<ForgotPasswordState?> GetForgotPasswordStateAsync(
this KeyCacheService keyCacheService,
string state,
CancellationToken ct = default
) =>
await keyCacheService.GetKeyAsync<ForgotPasswordState>(
$"forgot_password:{state}",
true,
ct
);
}
public record RegisterEmailState(
@ -98,4 +126,6 @@ public record RegisterEmailState(
[property: JsonProperty(NullValueHandling = NullValueHandling.Ignore)] Snowflake? ExistingUserId
);
public record ForgotPasswordState(string Email, Snowflake UserId);
public record AddExtraAccountState(AuthType AuthType, Snowflake UserId, string? Instance = null);