Commit af96232
fix(auth): key device metadata by inputUsername so alias sign-in pools remember devices (#4254)
* fix(auth): read device metadata with the caller's username during sign-in
`ConfirmDevice` stores device metadata under `signedInData.inputUsername`
(the username the caller signed in with), but the sign-in flow read it back
using `parameters["USERNAME"]` — the value Cognito echoes, which is the sub
for pools configured with alias sign-in.
On those pools the read never matched the write, so `DEVICE_KEY` was omitted
from the password-verifier response. Cognito treated every sign-in as a new
device: it returned fresh `NewDeviceMetadata`, `ConfirmDevice` stored it under
the email again, and the next sign-in repeated the cycle — MFA on every
sign-in and a new device record per attempt (one user had accumulated 50).
Pools where the username *is* the email are unaffected, since the two values
coincide there.
Reads now use the same value as the write:
- VerifyPasswordSRP: `inputUsername`
- VerifySignInChallenge (both call sites): `challenge.inputUsername ?? username`
Nothing sent to Cognito changes — `username` still supplies `USERNAME` on
every request; only the keychain lookups moved.
Known gap: the DeviceSRP actions (InitiateAuthDeviceSRP,
VerifyDevicePasswordSRP) still look up by the echoed username. That path only
executes once Cognito starts accepting the device key, so it is now reachable
and tracked separately.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
* fix(auth): delete device metadata with the same username used to read it
Commit 122689e changed the sign-in flow to read device metadata with the
caller's `inputUsername` (matching how `ConfirmDevice` writes it), but left the
`deviceNotFound` recovery paths deleting under `username` — the value Cognito
echoes, which is the sub for pools with alias sign-in.
When a stored device key is stale, Cognito rejects the password verifier with
`ResourceNotFoundException`. The recovery path then deletes the wrong keychain
entry, leaving the real one in place, so the retry re-reads the same stale key,
Cognito rejects it again, and sign-in loops indefinitely.
Read and delete now use the same value in both actions:
- VerifyPasswordSRP: `inputUsername`
- VerifySignInChallenge: `challenge.inputUsername ?? username`
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
* fix(auth): use inputUsername for device metadata in the device SRP flow
Once a device is remembered, Cognito answers the password verifier with
DEVICE_SRP_AUTH instead of an MFA challenge, routing sign-in through
InitiateAuthDeviceSRP / VerifyDevicePasswordSRP. Both looked the stored device
metadata up by the Cognito-echoed username (the sub, on pools with alias
sign-in) rather than the `inputUsername` it was written under, so the lookup
missed and the request omitted DEVICE_KEY — Cognito then rejected sign-in with
"Missing required parameter DEVICE_KEY".
- UserPoolSignInHelper: carry `inputUsername ?? username` into `.initiateDeviceSRP`
so InitiateAuthDeviceSRP reads (and re-sends) under the right key.
- VerifyDevicePasswordSRP: read metadata with `inputUsername`; the request still
sends `username` (the echoed value), which is what Cognito expects.
Completes the alias-pool device-remembering fix (see prior two commits); the
DEVICE_SRP_AUTH path is only reachable once DEVICE_KEY is accepted, so it could
not be exercised until the earlier read/delete fixes landed.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Co-authored-by: Harsh <6162866+harsh62@users.noreply.github.com>1 parent 75c52c6 commit af96232
4 files changed
Lines changed: 35 additions & 9 deletions
File tree
- AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin
- Actions/SignIn
- DeviceSRPAuth
- SRPAuth
- Support/Helpers
Lines changed: 5 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
43 | 47 | | |
44 | | - | |
| 48 | + | |
45 | 49 | | |
46 | 50 | | |
47 | 51 | | |
| |||
Lines changed: 11 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
56 | 61 | | |
57 | | - | |
| 62 | + | |
58 | 63 | | |
59 | 64 | | |
60 | 65 | | |
| |||
100 | 105 | | |
101 | 106 | | |
102 | 107 | | |
103 | | - | |
104 | | - | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
105 | 113 | | |
106 | 114 | | |
107 | 115 | | |
| |||
Lines changed: 12 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
75 | 75 | | |
76 | 76 | | |
77 | 77 | | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
78 | 81 | | |
79 | | - | |
| 82 | + | |
80 | 83 | | |
81 | 84 | | |
82 | 85 | | |
| |||
107 | 110 | | |
108 | 111 | | |
109 | 112 | | |
110 | | - | |
111 | | - | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
112 | 120 | | |
113 | 121 | | |
114 | 122 | | |
| |||
139 | 147 | | |
140 | 148 | | |
141 | 149 | | |
142 | | - | |
| 150 | + | |
143 | 151 | | |
144 | 152 | | |
145 | 153 | | |
| |||
Lines changed: 7 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
146 | 146 | | |
147 | 147 | | |
148 | 148 | | |
149 | | - | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
150 | 156 | | |
151 | 157 | | |
152 | 158 | | |
| |||
0 commit comments