Add user identity system with channel pairing and web /link command
Introduce Luna.Identity project with user identity service, pairing code generation, and channel linking. Channels (Telegram, CLI) now verify link status before routing messages and prompt users to pair via the web interface. WebChannel handles /link <channel-type> <code> commands to complete the pairing flow. Fix inverted expiration check in IsPairingCodeExpired that caused codes to be treated as expired immediately after creation.
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
namespace Luna.Identity.Abstractions;
|
||||
|
||||
/// <summary>
|
||||
/// Associates a channel-specific user identity with a Luna user.
|
||||
/// E.g., Telegram user ID "12345" → Luna user "guid-xxx"
|
||||
/// </summary>
|
||||
public record ChannelLink(
|
||||
string ChannelType,
|
||||
string ChannelUserId,
|
||||
string UserId,
|
||||
DateTimeOffset LinkedAt);
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace Luna.Identity.Abstractions;
|
||||
|
||||
public interface IPairingCodeGenerator
|
||||
{
|
||||
PairingCode Generate(string channelType, string userId);
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace Luna.Identity.Abstractions;
|
||||
|
||||
public interface IUserIdentityService
|
||||
{
|
||||
UserIdentity GetCurrentUser();
|
||||
string StartChannelLink(string userId, string channelType);
|
||||
void CompleteChannelLink(string userId, string channelType, string code);
|
||||
bool IsChannelLinked(string userId, string channelType);
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,12 @@
|
||||
namespace Luna.Identity.Abstractions;
|
||||
|
||||
/// <summary>
|
||||
/// A short-lived code used to link a new channel to an existing user.
|
||||
/// Generated on a trusted channel (e.g., web), confirmed from the channel being linked.
|
||||
/// </summary>
|
||||
public record PairingCode(
|
||||
string Code,
|
||||
string ChannelType,
|
||||
string UserId,
|
||||
DateTimeOffset CreatedAt,
|
||||
TimeSpan TimeToLive);
|
||||
@@ -0,0 +1,5 @@
|
||||
namespace Luna.Identity.Abstractions;
|
||||
|
||||
public record UserIdentity(
|
||||
string UserId,
|
||||
string UserName);
|
||||
Reference in New Issue
Block a user