71 lines
1.9 KiB
C#
71 lines
1.9 KiB
C#
using System;
|
|
using System.ComponentModel.DataAnnotations;
|
|
using System.ComponentModel.DataAnnotations.Schema;
|
|
using System.Text.Json;
|
|
using System.Text.Json.Serialization;
|
|
using DysonNetwork.Pass.Models;
|
|
using NodaTime;
|
|
|
|
namespace DysonNetwork.Pass.Features.Auth.Models;
|
|
|
|
public class AccountConnection : ModelBase
|
|
{
|
|
[Required]
|
|
public Guid AccountId { get; set; }
|
|
|
|
[ForeignKey(nameof(AccountId))]
|
|
[JsonIgnore]
|
|
public virtual Account Account { get; set; } = null!;
|
|
|
|
[Required]
|
|
[MaxLength(50)]
|
|
public string Provider { get; set; } = string.Empty;
|
|
|
|
[Required]
|
|
[MaxLength(256)]
|
|
public string ProviderId { get; set; } = string.Empty;
|
|
|
|
[MaxLength(256)]
|
|
public string? DisplayName { get; set; }
|
|
|
|
[MaxLength(1000)]
|
|
public string? AccessToken { get; set; }
|
|
|
|
[MaxLength(1000)]
|
|
public string? RefreshToken { get; set; }
|
|
|
|
public Instant? ExpiresAt { get; set; }
|
|
|
|
[Column(TypeName = "jsonb")]
|
|
public JsonDocument? ProfileData { get; set; }
|
|
|
|
public Instant ConnectedAt { get; set; } = SystemClock.Instance.GetCurrentInstant();
|
|
public Instant? LastUsedAt { get; set; }
|
|
|
|
[Column(TypeName = "jsonb")]
|
|
public JsonDocument? Metadata { get; set; }
|
|
|
|
public bool IsConnected => ExpiresAt == null || ExpiresAt > SystemClock.Instance.GetCurrentInstant();
|
|
|
|
public void UpdateTokens(string? accessToken, string? refreshToken, Instant? expiresAt)
|
|
{
|
|
AccessToken = accessToken;
|
|
RefreshToken = refreshToken;
|
|
ExpiresAt = expiresAt;
|
|
LastUsedAt = SystemClock.Instance.GetCurrentInstant();
|
|
}
|
|
|
|
public void Disconnect()
|
|
{
|
|
AccessToken = null;
|
|
RefreshToken = null;
|
|
ExpiresAt = null;
|
|
ConnectedAt = default; // Set to default value for Instant
|
|
}
|
|
|
|
public void UpdateProfileData(JsonDocument? profileData)
|
|
{
|
|
ProfileData = profileData;
|
|
}
|
|
}
|