backend phase 2: identity — phone-OTP auth, sessions & roles (REST)

- six REST endpoints (auth/request_otp, verify_otp, refresh, logout, me,
  me/select_role) wrapping the existing JWE/TOTP/RBAC engine
- usr.UserSessions with refresh-token rotation + stolen-token (replay)
  detection → revoke-all + 401; logout rotates the security stamp
- users extended: gender, national_id (enc, NULL until KYC),
  shahkar_verified_at (auto-reset on phone change), phone_hash UNIQUE,
  is_active, deleted_at + soft-delete filter; phone/email/national_id
  encrypted at rest via IFieldEncryptor value converter
- user_roles grant/revoke audit trail + global revoked filter; 7 roles
  seeded; admin sub-roles never self-assignable (403)
- ISmsSender seam (mock logs the OTP code) replaces the TODO log lines
- OperationResult/BaseController learned enveloped 401/403
- auth knobs as platform_configs rows (resend/attempts/session TTL)
- migration IdentitySessionsAndUserExtensions applied to the dev DB
- 24 new tests incl. Baya.Test.Api (WebApplicationFactory over SQLite);
  47 total green, zero new build warnings; swagger snapshot + contract
  (identity-auth.md), handoff, report, mocks-registry updated

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
hamid
2026-07-02 02:34:11 +03:30
parent 94fdcbe0d1
commit 3a51305343
88 changed files with 4619 additions and 91 deletions
+15
View File
@@ -54,6 +54,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Baya.Test.Foundation", "src\Tests\Baya.Test.Foundation\Baya.Test.Foundation.csproj", "{052BF207-440C-4FAB-AF6F-4992B29A3BF4}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Baya.Test.Api", "src\Tests\Baya.Test.Api\Baya.Test.Api.csproj", "{BD38DCB1-A00D-49D2-985C-AC34258365D8}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -220,6 +222,18 @@ Global
{052BF207-440C-4FAB-AF6F-4992B29A3BF4}.Release|x64.Build.0 = Release|Any CPU
{052BF207-440C-4FAB-AF6F-4992B29A3BF4}.Release|x86.ActiveCfg = Release|Any CPU
{052BF207-440C-4FAB-AF6F-4992B29A3BF4}.Release|x86.Build.0 = Release|Any CPU
{BD38DCB1-A00D-49D2-985C-AC34258365D8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BD38DCB1-A00D-49D2-985C-AC34258365D8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BD38DCB1-A00D-49D2-985C-AC34258365D8}.Debug|x64.ActiveCfg = Debug|Any CPU
{BD38DCB1-A00D-49D2-985C-AC34258365D8}.Debug|x64.Build.0 = Debug|Any CPU
{BD38DCB1-A00D-49D2-985C-AC34258365D8}.Debug|x86.ActiveCfg = Debug|Any CPU
{BD38DCB1-A00D-49D2-985C-AC34258365D8}.Debug|x86.Build.0 = Debug|Any CPU
{BD38DCB1-A00D-49D2-985C-AC34258365D8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BD38DCB1-A00D-49D2-985C-AC34258365D8}.Release|Any CPU.Build.0 = Release|Any CPU
{BD38DCB1-A00D-49D2-985C-AC34258365D8}.Release|x64.ActiveCfg = Release|Any CPU
{BD38DCB1-A00D-49D2-985C-AC34258365D8}.Release|x64.Build.0 = Release|Any CPU
{BD38DCB1-A00D-49D2-985C-AC34258365D8}.Release|x86.ActiveCfg = Release|Any CPU
{BD38DCB1-A00D-49D2-985C-AC34258365D8}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -247,6 +261,7 @@ Global
{7699705C-2C15-467F-957D-4C5EBE4FD92E} = {2373AFFC-1389-4D78-8465-074AB22084AF}
{704FAE1E-F0D2-468E-8B3D-E9E6F323ABE8} = {42CAB060-5D50-4E18-8F85-EBA5EB85B268}
{052BF207-440C-4FAB-AF6F-4992B29A3BF4} = {77986571-8153-4120-AD08-36729310A56B}
{BD38DCB1-A00D-49D2-985C-AC34258365D8} = {77986571-8153-4120-AD08-36729310A56B}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {05C223B9-EA89-44B2-B9F5-D01181F85DFE}