Files
step3/api/QuestionsApi/Models/ExternalAuthModels.cs
T

64 lines
1.9 KiB
C#

using MongoDB.Bson;
using MongoDB.Bson.Serialization.Attributes;
namespace QuestionsApi.Models;
public static class ExternalAuthProviders
{
public const string Steam = "steam";
public const string Google = "google";
public static bool Supported(string provider) => provider is Steam or Google;
}
public sealed class ExternalIdentity
{
[BsonId]
[BsonRepresentation(BsonType.ObjectId)]
public string Id { get; set; } = ObjectId.GenerateNewId().ToString();
public string UserId { get; set; } = "";
public string Provider { get; set; } = "";
public string Subject { get; set; } = "";
public string? Email { get; set; }
public bool EmailVerified { get; set; }
public DateTime CreatedUtc { get; set; }
public DateTime LastUsedUtc { get; set; }
}
public sealed class ExternalAuthTransaction
{
[BsonId] public string Id { get; set; } = "";
public string Provider { get; set; } = "";
public string Purpose { get; set; } = "login";
public string Status { get; set; } = "pending";
public string? Subject { get; set; }
public string? ProviderEmail { get; set; }
public bool EmailVerified { get; set; }
public string? UserId { get; set; }
public string? Nonce { get; set; }
public string? CodeVerifier { get; set; }
public string? Error { get; set; }
public DateTime CreatedUtc { get; set; }
public DateTime ExpiresUtc { get; set; }
}
public sealed class ExternalAuthStartRequest
{
public string Purpose { get; set; } = "login";
}
public sealed class CompleteExternalAuthRequest
{
public string TransactionId { get; set; } = "";
public string Action { get; set; } = "";
public string Username { get; set; } = "";
public string? Email { get; set; }
public string Password { get; set; } = "";
public bool AcceptLegal { get; set; }
}
public sealed record ExternalProviderClaims(
string Subject,
string? Email,
bool EmailVerified);