Plan 06 limen side resource authentication backend - #30
Merged
Conversation
Adds ResourceAuthPolicy, AllowlistedEmail, MagicLink, IssuedToken entities with EF configurations and ResourceAuth migration covering the four new tables.
Adds NSec (Ed25519), Konscious.Security.Cryptography (Argon2id), and MailKit packages to Limen.Infrastructure.
Implements ITokenSigner (Ed25519TokenSigner), IPasswordHasher (Argon2IdPasswordHasher), IMagicLinkSender (MagicLinkSender), and IResourceOidcStateStore (ResourceOidcStateStore) with their interfaces, AuthSettings options, and JwtBuilder service.
Registers Ed25519TokenSigner, Argon2IdPasswordHasher, MagicLinkSender, ResourceOidcStateStore, and JwtBuilder in AddInfrastructure.
Adds CQRS handlers for password login, magic link initiation and verification, resource OIDC initiation and callback, token revocation, and queries for revoked tokens, signing public key, and auth policy.
Adds ResourceAuthEndpoints with login-password, magic link, refresh, signout, revoked tokens, public key, resource-oidc stub, and admin revoke routes. Adds auth-policy GET and POST to RoutesEndpoints.
Adds unit tests for SetResourceAuthPolicyCommand, LoginWithPasswordCommand, VerifyMagicLinkCommand, GetRevokedTokensQuery, Ed25519TokenSigner, and Argon2IdPasswordHasher. 22 new tests, all green.
Add Verify method to ITokenSigner and implement in Ed25519TokenSigner. Call signer.Verify at the top of /auth/refresh and /auth/signout before trusting any cookie claims. Remove dead ?? fallbacks for authMethod and cookieScope. Add Verify_AcceptsValidJwt, Verify_RejectsTamperedPayload, and Verify_RejectsMalformedJwt tests to Ed25519TokenSignerTests.
When SMTP is not configured, throw InvalidOperationException unless Auth:LogMagicLinksInDev is explicitly set to true. Demote the log call to LogDebug with a comment marking it as an OPERATOR-VISIBLE dev fallback that must never be used in production. Add LogMagicLinksInDev (default false) and CookieSecure (default true) to AuthSettings.
Replace tracked UsedAt assignment with ExecuteUpdateAsync conditioned on UsedAt == null. Add SupportsBulkUpdate to IAppDbContext so handlers can fall back to the tracker-based update when running against the in-memory provider in tests.
Throw InvalidOperationException at the top of InitiateMagicLinkCommand handler when AuthSettings.PublicBaseUrl is missing. Also add AuthSettingsValidator (IValidateOptions<AuthSettings>) that fails startup if SigningKeyPath is absent, registered via AddApplication.
Add MaxEntries cap of 10,000 and PruneExpired helper called on each Put. Throw InvalidOperationException if the store is at capacity after pruning. Add XML doc noting the store is single-instance only.
Call _hasher.Verify against a dummy Argon2id hash and discard the result when the policy is absent, so the response time does not leak whether a route has password auth configured.
Replace int.Parse with int.TryParse for each PHC parameter field and log a structured warning on parse failure instead of silently returning false. Add ILogger<Argon2IdPasswordHasher> constructor dependency. Update test to pass NullLogger.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Ostiarius middleware and frontend policy editor are follow-up PRs.
Closes #29