✨ Authorized device
This commit is contained in:
@@ -26,6 +26,7 @@ public class AuthController(
|
|||||||
[Required] public ClientPlatform Platform { get; set; }
|
[Required] public ClientPlatform Platform { get; set; }
|
||||||
[Required] [MaxLength(256)] public string Account { get; set; } = null!;
|
[Required] [MaxLength(256)] public string Account { get; set; } = null!;
|
||||||
[Required] [MaxLength(512)] public string DeviceId { get; set; } = null!;
|
[Required] [MaxLength(512)] public string DeviceId { get; set; } = null!;
|
||||||
|
[MaxLength(1024)] public string? DeviceName { get; set; }
|
||||||
public List<string> Audiences { get; set; } = new();
|
public List<string> Audiences { get; set; } = new();
|
||||||
public List<string> Scopes { get; set; } = new();
|
public List<string> Scopes { get; set; } = new();
|
||||||
}
|
}
|
||||||
@@ -57,7 +58,7 @@ public class AuthController(
|
|||||||
.FirstOrDefaultAsync();
|
.FirstOrDefaultAsync();
|
||||||
if (existingChallenge is not null) return existingChallenge;
|
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
|
var challenge = new AuthChallenge
|
||||||
{
|
{
|
||||||
ExpiredAt = Instant.FromDateTimeUtc(DateTime.UtcNow.AddHours(1)),
|
ExpiredAt = Instant.FromDateTimeUtc(DateTime.UtcNow.AddHours(1)),
|
||||||
|
@@ -105,6 +105,7 @@ public class AuthService(
|
|||||||
public async Task<AuthClient> GetOrCreateDeviceAsync(
|
public async Task<AuthClient> GetOrCreateDeviceAsync(
|
||||||
Guid accountId,
|
Guid accountId,
|
||||||
string deviceId,
|
string deviceId,
|
||||||
|
string? deviceName = null,
|
||||||
ClientPlatform platform = ClientPlatform.Unidentified
|
ClientPlatform platform = ClientPlatform.Unidentified
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
@@ -116,6 +117,7 @@ public class AuthService(
|
|||||||
DeviceId = deviceId,
|
DeviceId = deviceId,
|
||||||
AccountId = accountId
|
AccountId = accountId
|
||||||
};
|
};
|
||||||
|
if (deviceName is not null) device.DeviceName = deviceName;
|
||||||
db.AuthClients.Add(device);
|
db.AuthClients.Add(device);
|
||||||
await db.SaveChangesAsync();
|
await db.SaveChangesAsync();
|
||||||
|
|
||||||
|
@@ -14,6 +14,7 @@ public class AppleMobileConnectRequest
|
|||||||
|
|
||||||
public class AppleMobileSignInRequest : AppleMobileConnectRequest
|
public class AppleMobileSignInRequest : AppleMobileConnectRequest
|
||||||
{
|
{
|
||||||
[Required]
|
[Required] [MaxLength(512)]
|
||||||
public required string DeviceId { get; set; }
|
public required string DeviceId { get; set; }
|
||||||
|
[MaxLength(1024)] public string? DeviceName { get; set; }
|
||||||
}
|
}
|
||||||
|
@@ -96,7 +96,8 @@ public class OidcController(
|
|||||||
userInfo,
|
userInfo,
|
||||||
account,
|
account,
|
||||||
HttpContext,
|
HttpContext,
|
||||||
request.DeviceId
|
request.DeviceId,
|
||||||
|
request.DeviceName
|
||||||
);
|
);
|
||||||
|
|
||||||
return Ok(challenge);
|
return Ok(challenge);
|
||||||
|
@@ -191,7 +191,8 @@ public abstract class OidcService(
|
|||||||
OidcUserInfo userInfo,
|
OidcUserInfo userInfo,
|
||||||
Account.Account account,
|
Account.Account account,
|
||||||
HttpContext request,
|
HttpContext request,
|
||||||
string deviceId
|
string deviceId,
|
||||||
|
string? deviceName = null
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
// Create or update the account connection
|
// Create or update the account connection
|
||||||
@@ -217,7 +218,7 @@ public abstract class OidcService(
|
|||||||
|
|
||||||
// Create a challenge that's already completed
|
// Create a challenge that's already completed
|
||||||
var now = SystemClock.Instance.GetCurrentInstant();
|
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
|
var challenge = new AuthChallenge
|
||||||
{
|
{
|
||||||
ExpiredAt = now.Plus(Duration.FromHours(1)),
|
ExpiredAt = now.Plus(Duration.FromHours(1)),
|
||||||
|
Reference in New Issue
Block a user