Repository navigation
Support the self-service credential change and recent sign-in - #195
PasinduYeshan wants to merge 4 commits into
Conversation
A completed embedded sign-in, sign-up or organization unit switch returns a flow assertion. Exchange it at the token endpoint (RFC 8693, subject token type JWT, no scope) for an access token and replace the session with it, keeping the assertion as the ID token. One core method, exchangeFlowAssertion, serves the React and Vue clients, the browser organization unit switch, the Next.js sign-in action and the Nuxt sign-in route. Embedded mode now needs clientId, checked at initialization, and the application needs the token exchange grant; without it the sign-in fails with an error that names the grant and keeps no session. Signed-off-by: PasinduYeshan <[email protected]>
- When the assertion exchange fails, drop the SSO session handles the completing step returned, so a retry shows the flow again, and report the failure to the sign-in-failed hook. - Check clientId after the client is set up, and end the wait of every caller when initialization is refused. - Stop the previous session's refresh timer when an embedded session replaces it. - Take the session identity from the new assertion in the Next.js sign-in action and in the Nuxt session cookie, not from an ID token stored for the same session ID. Signed-off-by: PasinduYeshan <[email protected]>
The release commit left changelog lines that format:check rejects, which fails the PR builder. Signed-off-by: PasinduYeshan <[email protected]>
|
Important Review skippedToo many files! This PR contains 120 files, which is 20 over the limit of 100. To get a review, reduce the PR to 100 files or fewer by splitting it into smaller PRs or changing its base branch. Upgrade to a paid plan to raise the limit. This organization's CodeRabbit subscription is cancelled. Resubscribe in Billing to continue reviews beyond the free-tier limit.
|
🔀 Cross-SDK feature parity, ports raisedThis pull request is labelled Ports (DO NOT EDIT)
3 of 3 sibling SDKs accounted for. Every sibling SDK is accounted for. The contract is in the SDK development specification. |
POST /users/me/update-credentials takes {name, currentValue, newValue}. A credential the user
holds needs its current value. One the user does not hold yet, and an email or mobile change,
needs a recent sign-in: the server answers 401 with an insufficient_user_authentication
challenge and max_age.
The SDKs send the new body, show the current-value errors on the current-value field, and turn
the challenge into a StepUpRequiredError with maxAge. ChangeCredential and UserProfile sign the
user in again and send the change once more: a popup for a redirect session, the sign-in flow
in a dialog for an embedded session. Next.js and Nuxt hold the session on the server: their
components pass the challenge to the app, and a redirect sign-in forwards max_age and
prompt=login.
Signed-off-by: PasinduYeshan <[email protected]>
eae5c92 to
9adc16f
Compare
|
Purpose
ThunderID changed how users change their own credentials (thunder-id/thunderid#7086):
POST /users/me/update-credentialstakes one credential per request:{"name", "currentValue", "newValue"}. The old{"attributes": {...}}body is refused with400 USR-1017, so every released SDK fails to change a credential today.400 USR-1047, wrong is403 USR-1048.emailormobileattribute onPUT /users/me, need a recent sign-in (180 seconds by default). Otherwise the server answers401withWWW-Authenticate: Bearer error="insufficient_user_authentication", max_age="180".POST /flow/executetakesmaxAgewhen it starts anAUTHENTICATIONflow, and asks the user again when their sign-in is older.This pull request sends the new body, shows the current-value errors where the user can act on them, and handles the recent sign-in challenge:
ChangeCredentialandUserProfilesign the user in again and send the change once more.🔧 Summary of Breaking Changes
The credential change takes one credential with its current value, not a map of new values.
💥 Impact
These take
UpdateMeCredentialsPayload({name, currentValue?, newValue}) instead ofRecord<string, string>:updateMeCredentials({payload})in@thunderid/javascriptupdateUserCredentials(payload, userId?)on the browser, Node, Next.js and Nuxt clientsupdateUserCredentialsFromRequest(req, payload)in@thunderid/expressPATCH /api/auth/user/credentialsbody ({payload: {...}})The components need no change from apps. The old shape fails against any ThunderID that has #7086.
🔄 Migration Guide
Leave
currentValueout when the user sets the credential for the first time. CatchStepUpRequiredError(or callrunWithStepUp) to handle the recent sign-in challenge.Approach
Core (
@thunderid/javascript)updateMeCredentialssends{name, currentValue, newValue};currentValueonly when it is not empty. An empty name or new value is refused before any request.createApiResponseErrorbuilds the thrownThunderIDAPIErrorfrom the server's error body: its code, and itsmessage.defaultValueas the message. On a401withinsufficient_user_authentication(read fromWWW-Authenticate, or from theAUTH-4011body when the header is not readable), it throwsStepUpRequiredErrorwithmaxAge.parseAuthenticationChallengereads the header.runWithStepUp(send, {reauthenticate, isActive})sends a change, signs the user in again onStepUpRequiredError, and sends it once more. It never sends a third time, and it does not resend after the caller's form has closed (JS-STEP_UP-AB01).mapCredentialUpdateErrorandmapReauthenticationErrorturn the codes into translated messages for the components.USR-1047andUSR-1048go to the current-value field.pickRecentSignInParamskeeps onlymax_age(whole seconds) andprompt=loginfrom sign-in options, for the server SDKs.maxAgeonEmbeddedSignInFlowInitiateRequest.Browser (
@thunderid/browser)reauthenticate({maxAge})for a session from a redirect sign-in: opens a popup at once (so the browser does not block it) with an authorization request that carries PKCE, a newstateandnonce,max_age(orprompt=loginwithout one) andid_token_hint. It replaces the session only when thestate,nonceandsubmatch the request and the signed-in user, and never uses the refresh token for it. The refresh timer pauses while the popup is open. The page in the popup hands the code to its opener and closes.executeReauthenticationFlow(payload, {maxAge})for a session from an embedded sign-in: starts anAUTHENTICATIONflow withmaxAge(0when the challenge has none) and the kept SSO session handles, then continues it step by step. When it completes for the samesub, the assertion is exchanged as in Keep an access token after an embedded sign-in #193 and replaces the session; another user's sign-in is refused withBROWSER-REAUTHENTICATION-DU01and the session stays.getReauthenticationMethod():popup,flow(a session from an embedded sign-in, ormode: 'embedded') orunavailable(backend mode). A session from an embedded sign-in is marked withembedded_sign_in, which Keep an access token after an embedded sign-in #193'ssetSessionFromFlowAssertionnow writes and any token endpoint response clears.signIndoes.React and Vue
useThunderID().reauthenticate({maxAge})opens the popup for a redirect session, and otherwise shows a re-sign-in dialog that runs the flow withBaseSignIn, including a passkey step. A sign-in option that would leave the page (a federated sign-in) is not followed: the flow starts again and says to choose another option. A flow that cannot go on starts again once, then ends the re-sign-in. Closing the dialog rejects with…-REAUTHENTICATION-CN01.ChangeCredentialhas an optional current-value field (hint: "Leave this empty if you have not set one yet.").ChangeCredentialandUserProfileuserunWithStepUp. When the app setsonReauthenticationRequired(Vue:@reauthentication-required), they call it instead and do not retry.updateMeProfileuses the SDK's HTTP client fetcher, so a401reaches the step-up handling instead of a generic error.Server SDKs
@thunderid/nextjsand@thunderid/nuxthold the session on the server, so they do not sign the user in again in the page; theirreauthenticaterejects (Nuxt:NUXT-REAUTHENTICATION-UM01).ChangeCredentialhas the current-value field.ChangeCredentialandUserProfileshow "Sign in again to save this change." on a step-up and pass the challenge toonReauthenticationRequired(Nuxt: thereauthentication-requiredevent).updateUserProfileActionand Nuxt'sPATCH /api/auth/user/profilereturn the challenge.max_ageandprompt=login(Next.jssignInAction, NuxtGET /api/auth/signinand the plugin'ssignIn(options)), so the app can sign the user in again and the user saves once more. With either option, Next.js starts a new session for the sign-in, as Nuxt does, so a signed-in user's callback replaces the session cookie. Other options are not sent on a redirect sign-in, and a payload withexecutionId,applicationIdorflowTypestill starts the embedded flow.@thunderid/nodeand@thunderid/express: the new payload.Not covered here:
Known follow-ups: thunder-id/thunderid#7122 (sign in again within the session's organization unit) and thunder-id/thunderid#7123 (use PAR for the popup when the server requires it).
Proof
Run against a server built from thunderid
mainwith #7086 (make run, 180 s recent sign-in window), with a React page served from this branch and driven by Playwright in Chrome.Every check passed: 11 in redirect mode, 13 in embedded mode. The user's last sign-in was more than 180 s old for every case below except the held password.
400, wrong403, right204. No re-sign-in.at+jwt401, sign in again, the change is sent once more and saved (204), newerauth_timefor the samesubUserProfile:401, sign in again,PUT /users/me200In embedded mode the dialog starts the flow with
{"flowType":"AUTHENTICATION","maxAge":180}, themaxAgefrom the challenge.Run logs
Related Issues
Related PRs
Checklist
breaking changelabel added.parity/prs-raisedorparity/prs-not-neededadded.parity/prs-raised, the port links are posted as a reply on the parity check's comment.Security checks