/ GUNRPG.Core / Identity / DeviceCode.cs
DeviceCode.cs
 1  namespace GUNRPG.Core.Identity;
 2  
 3  /// <summary>
 4  /// Represents a pending Device Code flow session for console clients.
 5  /// The console displays a short user code; the user visits the verification URI
 6  /// and completes WebAuthn in the browser; the console polls for completion.
 7  /// </summary>
 8  public sealed class DeviceCode
 9  {
10      public Guid Id { get; set; } = Guid.NewGuid();
11  
12      /// <summary>
13      /// Opaque device code returned to the console client.
14      /// Long random value — never shown to the user.
15      /// </summary>
16      public string Code { get; set; } = string.Empty;
17  
18      /// <summary>
19      /// Short user-friendly code the user enters at the verification URI (e.g. "WXYZ-1234").
20      /// </summary>
21      public string UserCode { get; set; } = string.Empty;
22  
23      /// <summary>Verification URI the user navigates to in their browser.</summary>
24      public string VerificationUri { get; set; } = string.Empty;
25  
26      public DateTimeOffset IssuedAt { get; set; } = DateTimeOffset.UtcNow;
27  
28      public DateTimeOffset ExpiresAt { get; set; }
29  
30      /// <summary>
31      /// Set once the user successfully authenticates in the browser.
32      /// The polling console client exchanges this for a token pair.
33      /// </summary>
34      public string? AuthorizedUserId { get; set; }
35  
36      public bool IsAuthorized => AuthorizedUserId is not null;
37  
38      public bool IsExpired => ExpiresAt <= DateTimeOffset.UtcNow;
39  
40      /// <summary>
41      /// Minimum seconds the console must wait between poll requests (rate limiting).
42      /// </summary>
43      public int PollIntervalSeconds { get; set; } = 5;
44  
45      /// <summary>Timestamp of the most recent poll — used to enforce the poll interval.</summary>
46      public DateTimeOffset? LastPolledAt { get; set; }
47  }