From 1778ab112dd900ac47b552e1a4ed4e22bf6c4fd3 Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Thu, 14 Aug 2025 02:21:59 +0800 Subject: [PATCH] :sparkles: Authorized device --- DysonNetwork.Pass/Auth/AuthController.cs | 3 ++- DysonNetwork.Pass/Auth/AuthService.cs | 2 ++ DysonNetwork.Pass/Auth/OpenId/AppleMobileSignInRequest.cs | 3 ++- DysonNetwork.Pass/Auth/OpenId/OidcController.cs | 3 ++- DysonNetwork.Pass/Auth/OpenId/OidcService.cs | 5 +++-- 5 files changed, 11 insertions(+), 5 deletions(-) diff --git a/DysonNetwork.Pass/Auth/AuthController.cs b/DysonNetwork.Pass/Auth/AuthController.cs index a4307e7..0cf2894 100644 --- a/DysonNetwork.Pass/Auth/AuthController.cs +++ b/DysonNetwork.Pass/Auth/AuthController.cs @@ -26,6 +26,7 @@ public class AuthController( [Required] public ClientPlatform Platform { get; set; } [Required] [MaxLength(256)] public string Account { get; set; } = null!; [Required] [MaxLength(512)] public string DeviceId { get; set; } = null!; + [MaxLength(1024)] public string? DeviceName { get; set; } public List Audiences { get; set; } = new(); public List Scopes { get; set; } = new(); } @@ -57,7 +58,7 @@ public class AuthController( .FirstOrDefaultAsync(); if (existingChallenge is not null) return existingChallenge; - var device = await auth.GetOrCreateDeviceAsync(account.Id, request.DeviceId, request.Platform); + var device = await auth.GetOrCreateDeviceAsync(account.Id, request.DeviceId, request.DeviceName, request.Platform); var challenge = new AuthChallenge { ExpiredAt = Instant.FromDateTimeUtc(DateTime.UtcNow.AddHours(1)), diff --git a/DysonNetwork.Pass/Auth/AuthService.cs b/DysonNetwork.Pass/Auth/AuthService.cs index 0215348..32f004a 100644 --- a/DysonNetwork.Pass/Auth/AuthService.cs +++ b/DysonNetwork.Pass/Auth/AuthService.cs @@ -105,6 +105,7 @@ public class AuthService( public async Task GetOrCreateDeviceAsync( Guid accountId, string deviceId, + string? deviceName = null, ClientPlatform platform = ClientPlatform.Unidentified ) { @@ -116,6 +117,7 @@ public class AuthService( DeviceId = deviceId, AccountId = accountId }; + if (deviceName is not null) device.DeviceName = deviceName; db.AuthClients.Add(device); await db.SaveChangesAsync(); diff --git a/DysonNetwork.Pass/Auth/OpenId/AppleMobileSignInRequest.cs b/DysonNetwork.Pass/Auth/OpenId/AppleMobileSignInRequest.cs index c655a88..ad5a15f 100644 --- a/DysonNetwork.Pass/Auth/OpenId/AppleMobileSignInRequest.cs +++ b/DysonNetwork.Pass/Auth/OpenId/AppleMobileSignInRequest.cs @@ -14,6 +14,7 @@ public class AppleMobileConnectRequest public class AppleMobileSignInRequest : AppleMobileConnectRequest { - [Required] + [Required] [MaxLength(512)] public required string DeviceId { get; set; } + [MaxLength(1024)] public string? DeviceName { get; set; } } diff --git a/DysonNetwork.Pass/Auth/OpenId/OidcController.cs b/DysonNetwork.Pass/Auth/OpenId/OidcController.cs index d21cfd8..a165757 100644 --- a/DysonNetwork.Pass/Auth/OpenId/OidcController.cs +++ b/DysonNetwork.Pass/Auth/OpenId/OidcController.cs @@ -96,7 +96,8 @@ public class OidcController( userInfo, account, HttpContext, - request.DeviceId + request.DeviceId, + request.DeviceName ); return Ok(challenge); diff --git a/DysonNetwork.Pass/Auth/OpenId/OidcService.cs b/DysonNetwork.Pass/Auth/OpenId/OidcService.cs index 14aa738..257f285 100644 --- a/DysonNetwork.Pass/Auth/OpenId/OidcService.cs +++ b/DysonNetwork.Pass/Auth/OpenId/OidcService.cs @@ -191,7 +191,8 @@ public abstract class OidcService( OidcUserInfo userInfo, Account.Account account, HttpContext request, - string deviceId + string deviceId, + string? deviceName = null ) { // Create or update the account connection @@ -217,7 +218,7 @@ public abstract class OidcService( // Create a challenge that's already completed var now = SystemClock.Instance.GetCurrentInstant(); - var device = await auth.GetOrCreateDeviceAsync(account.Id, deviceId); + var device = await auth.GetOrCreateDeviceAsync(account.Id, deviceId, deviceName, ClientPlatform.Ios); var challenge = new AuthChallenge { ExpiredAt = now.Plus(Duration.FromHours(1)),