Skip to content

✨ feat(auth-microservice, cognito-triggers) [OTP rev 3]: CUSTOM_AUTH sign-in code sent by PRMS (do not merge before the pool triggers are wired) - #40

Merged
JuankCadavid merged 2 commits into
dev-authfrom
dev-auth-otp
Sep 12, 2026
Merged

JuankCadavid merged 2 commits into
dev-authfrom
dev-auth-otp

Conversation

@JuankCadavid

Copy link
Copy Markdown
Contributor

⚠️ Merge order

Do not merge until OTP-T-14 steps 1–4 are done (Lambdas deployed and wired to pool us-east-1_o9y9Yq5pO, general-client AuthSessionValidity = 5 min). This PR switches the microservice from USER_AUTH/EMAIL_OTP to CUSTOM_AUTH; merging first would break the Center sign-in on TEST until the triggers exist.

What

Pivot decided 2026-09-11 (OTP-OQ-8, Option B): the sign-in code is generated by PRMS-owned Cognito triggers and emailed through PRMS's notification pipeline from PRMS-No-reply@cgiar.org as "PRMS Reporting Tool" — no Cognito default sender, no spam, no 50/day pool quota.

  • cognito-triggers/ (new package, da73833): DefineAuthChallenge / CreateAuthChallenge / VerifyAuthChallengeResponse — crypto.randomInt 6-digit code, reuse across retries, 3 attempts, timingSafeEqual, fake challenge for unknown users, email via the RabbitMQ send pattern with the auth envelope (same shape auth-microservice uses), SAM template + README (deploy, pool wiring from a before-export, troubleshooting). 111 tests.
  • auth-microservice (dda504f): CognitoService drives CUSTOM_AUTH / CUSTOM_CHALLENGE; a wrong code returns 401 CODE_MISMATCH with the rotated session; NotAuthorized mapping → ATTEMPTS_EXCEEDED / CODE_EXPIRED / NOT_AUTHORIZED; Swagger + README updated. Routes, DTOs, filters, interceptor unchanged. 368 tests.

Deploy notes (TEST)

Triggers env: MS_NOTIFICATION_HOST (or MS_RMQ_HOST/USER/PASSWORD), MS_NOTIFICATION_QUEUE, MS_NOTIFICATION_USER/PASSWORD, EMAIL_SENDER, APP_URL. Pool: attach the three triggers (console or --cli-input-json from a fresh export — never a bare update-user-pool). After go-live, roll back the EMAIL_OTP first factor enabled by OTP-T-1.

Spec: PRMS docs/specs/changes/cognito-email-otp-login (design §18, tasks T-11..T-14).

🤖 Generated with Claude Code

JuankCadavid and others added 2 commits September 11, 2026 20:11
…gh Cognito CUSTOM_AUTH / CUSTOM_CHALLENGE

- start: InitiateAuth CUSTOM_AUTH (no PREFERRED_CHALLENGE, no SELECT_CHALLENGE round-trip), expects CUSTOM_CHALLENGE
- verify: RespondToAuthChallenge CUSTOM_CHALLENGE with ANSWER; a wrong code returns 401 CODE_MISMATCH carrying the rotated session; NotAuthorized mapping → ATTEMPTS_EXCEEDED / CODE_EXPIRED / NOT_AUTHORIZED; missing Session → CHALLENGE_NOT_SUPPORTED; empty AuthenticationResult → UPSTREAM_ERROR
- Swagger and README contract updated; request-level hygiene test on the 401-with-session path

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…gers package (Define / Create / Verify) with the PRMS-branded code email

- DefineAuthChallenge: one CUSTOM_CHALLENGE per session, tokens on a correct answer, failAuthentication after 3 misses, fake challenge for unknown users
- CreateAuthChallenge: crypto.randomInt 6-digit code, reuse across retries via challengeMetadata, masked destination, email emitted to the notification queue with the auth envelope (from PRMS-No-reply, name "PRMS Reporting Tool"), queue failure → email_failed but the challenge still returns
- VerifyAuthChallengeResponse: timingSafeEqual, always false for unknown users
- amqplib-only runtime dep; confirm channel + waitForConfirms; NestJS event envelope { pattern, data }; logs = allow-listed keys only
- SAM template (Node 22, Timeout 5 s, pool-scoped cognito-idp invoke permission) + README (deploy, pool wiring via before-export, troubleshooting)

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@sonarqubecloud

Copy link
Copy Markdown

@JuankCadavid
JuankCadavid merged commit 4c832f2 into dev-auth Sep 12, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant