Repository navigation
feat(auth): Add progressive invitation acceptance - #125910
Conversation
23e141b to
d79166b
Compare
d79166b to
8820cba
Compare
8820cba to
f849bcc
Compare
| function mockInvite(body: InviteDetails | (() => InviteDetails)) { | ||
| return MockApiClient.addMockResponse({ | ||
| url: '/accept-invite/org-slug/1/abc/', | ||
| method: 'GET', | ||
| body, | ||
| }); | ||
| } |
a8c2877 to
38b2b2b
Compare
| const authConfigQuery = useQuery({ | ||
| ...authConfigQueryOptions, | ||
| enabled: needsAccountAuthentication, | ||
| }); |
There was a problem hiding this comment.
Refresh wipes pending MFA state
Medium Severity
The invite GET still runs initiate_login, which deletes _pending_2fa before /auth/config/ is fetched. A refresh during inline MFA therefore loses the pending challenge and shows the registration form instead. The acceptance: 'explicit' query is sent but is not handled on the backend, so it does not skip that reset.
Reviewed by Cursor Bugbot for commit 38b2b2b. Configure here.
38b2b2b to
c4b3db3
Compare
Keep invitation acceptance compatible with the existing screen while the
composed authentication flow rolls out.
Clients can opt in with `GET
/api/0/accept-invite/{organization}/{member}/{token}/?acceptance=explicit`.
The opt-in is stored with the pending invitation in the session. MFA
enrollment then leaves that invitation pending for an explicit
acceptance POST. Clients using the default request retain automatic
acceptance after enrollment. Session cleanup removes the opt-in, and
loading another invitation with the default behavior resets it.
The opted-in request also preserves a pending MFA login challenge when
the invitation page is reloaded. Authentication and acceptance
validation remain unchanged, and organization SSO continues to accept
through its provider pipeline.
Deploy this backend change before the frontend opt-in in #125910.
Verification: 67 scoped backend tests pass, covering existing automatic
acceptance, explicit TOTP/SMS/security-key enrollment, subsequent
explicit acceptance, invalid invitations, session scoping, and pending
MFA preservation. Backend typing and lint checks pass. The composed flow
was also tested against this backend with all eight browser acceptance
journeys passing.
| <Alert variant="danger">{t('Unable to load this invitation. Try again.')}</Alert> | ||
| <Button | ||
| busy={state.isRetrying} | ||
| disabled={state.isRetrying} | ||
| onClick={actions.retryInvitation} | ||
| > | ||
| {t('Try again')} | ||
| </Button> |
There was a problem hiding this comment.
Isn't there a LoadingError component or something here we can use?
Add the signed-in account badge used by the branded invitation flow. Showing the account name and email helps users confirm which account will join the organization; the parent owns account switching and invitation refreshes. Includes a focused interaction test and a component story. This component lands ahead of the route change in #125910, so the existing invitation screen remains active.
## Summary Add `InvitationAuthentication`, the account-creation and sign-in step for the composed invitation acceptance page. Invitees can authenticate within the invitation screen, then review and explicitly accept the invitation using the account they authenticated with. This component composes the registration and account-authentication forms used by the branded auth views. Keeping their form handling, authentication requests, provider links, and MFA UI shared lets fixes to the main authentication flow carry through to invitation acceptance. ## Flow - Start with `RegistrationForm`, prefilled with the invitation email. Its `secondaryAction` renders “Have an account? Sign in” using a translated link-style button. - Switch to `AccountAuthentication` for password sign-in and the external-provider links supplied by `authConfig`. “Don't have an account? Create one” returns to registration. - When password sign-in requires MFA, keep the challenge inline and wait for MFA completion before reporting authentication. A pending challenge supplied by `authConfig` takes precedence over the initial registration view, allowing the parent to restore an in-progress sign-in. - During MFA, hide the registration switch. “Back to Login” uses the shared MFA cancellation request and returns to password sign-in. Local cancellation state overrides the initial pending-MFA configuration so the canceled challenge is not immediately redisplayed. - Animate transitions between registration, password sign-in, and MFA using the shared motion timing. Invitation registration remains available when public signup is disabled; account creation continues to be authorized by the backend invitation session. ## Component boundary `InvitationAuthentication` owns registration/sign-in navigation and the local MFA-method state. It receives authentication configuration and the initial registration email from its parent. Successful registration, password sign-in, or MFA completion calls `onAuthenticated` with the authenticated account and destination. The wrapper delegates the next step to the parent: the invitation page refreshes the invitation requirements and presents acceptance. Invitation fetching, organization SSO, account switching, acceptance, and final navigation belong to the surrounding flow. This PR adds the component, its focused tests, and an interactive story. Route wiring and page orchestration are introduced in #125910, allowing this authentication step to be reviewed independently. ## Verification Focused component tests cover prefilled registration and navigation in both directions, successful registration without navigation, password sign-in and configured provider links when public signup is disabled, MFA completion before reporting authentication, and cancellation of a pending MFA challenge. The story documents the component's props and demonstrates the registration/sign-in UI.
c4b3db3 to
6e279c8
Compare
6e279c8 to
3f88b92
Compare
| self.browser.driver.execute_script( | ||
| """ | ||
| const form = document.createElement('form'); | ||
| form.method = 'POST'; | ||
| form.action = '/auth/sso/'; | ||
|
|
||
| const input = document.createElement('input'); | ||
| input.name = 'email'; | ||
| input.value = arguments[0]; | ||
| form.appendChild(input); | ||
|
|
||
| const csrfInput = document.createElement('input'); | ||
| csrfInput.name = 'csrfmiddlewaretoken'; | ||
| csrfInput.value = arguments[1]; | ||
| form.appendChild(csrfInput); | ||
|
|
||
| document.body.appendChild(form); | ||
| form.submit(); | ||
| """, | ||
| email, | ||
| csrf_cookie["value"], | ||
| ) |
There was a problem hiding this comment.
Why do we need this javascript?
3f88b92 to
4aeae9b
Compare
4aeae9b to
b85a826
Compare
There was a problem hiding this comment.
can get rid of this
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
There are 3 total unresolved issues (including 2 from previous reviews).
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit a5b5c05. Configure here.
| authConfig={loginConfig} | ||
| initialEmail={initialEmail} | ||
| onAuthenticated={actions.handleAuthenticated} | ||
| /> |
There was a problem hiding this comment.
Social login abandons optional-SSO invites
Medium Severity
Social login leaves the invitation page, but optional-SSO organizations store a session next of / and this flow opts into acceptance=explicit. After Google, GitHub, or Azure authentication the user lands on / without membership and without a way to accept.
Additional Locations (2)
Reviewed by Cursor Bugbot for commit a5b5c05. Configure here.
| path: 'accept/:orgId/:memberId/:token/', | ||
| component: make(() => import('sentry/views/authV2/acceptOrganizationInvite')), |
There was a problem hiding this comment.
Bug: The new route path accept/:orgId/:memberId/:token/ mismatches the actual invitation URL /accept-invite/..., which will cause invitation links to result in a 404 error.
Severity: CRITICAL
Suggested Fix
In static/app/views/authV2/routes.tsx, update the route path from path: 'accept/:orgId/:memberId/:token/' to path: 'accept-invite/:orgId/:memberId/:token/' to match the URL pattern used in user invitation links.
Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.
Location: static/app/views/authV2/routes.tsx#L16-L17
Potential issue: The new route for accepting organization invitations is defined with
the path `accept/:orgId/:memberId/:token/`. However, the actual invitation links sent to
users, and the corresponding API endpoints, use the path prefix `/accept-invite/`. Since
the old route for `/accept-invite/` is no longer registered in the main router, users
clicking on invitation links will encounter a 404 error, preventing them from accepting
the invitation and joining the organization.


Move organization invitation acceptance under the branded authentication layout and compose the invitation account badge, account authentication, and status components introduced earlier in this stack.
Signed-out users can create an account or sign in, including MFA, within the invitation screen. Authentication refreshes the invitation before presenting acceptance. Organization SSO accepts the invitation through the provider pipeline and lands in the organization. Signed-in users see the account they are accepting with and can switch accounts inline.
useInvitationFlowowns fetching, authentication completion, account switching, acceptance, and the derived view state. The page renders that state with a sharedInvitationLayout, whilegetInvitationStepselects the authentication or acceptance step independently of the status component.The invitation query opts into explicit acceptance. MFA enrollment in a separate tab leaves the invitation pending, and returning to the invitation refetches its requirements before offering acceptance. Temporary invitation, organization-config, and authentication-config failures show a retry action; invalid or expired invitations retain their account-switch action. A failed refresh after logout keeps the previous account hidden.
Retain the legacy invitation component and its unit tests for a follow-up cleanup.
Backend dependency: #126028 is merged and included in this stack’s base, so browser CI exercises the compatibility behavior. It preserves default automatic acceptance for existing clients while enabling explicit acceptance and preserving pending MFA challenges for this flow. Deploy that backend change before landing this frontend change.
Verification: all eight browser acceptance journeys pass using the default auth configuration against that backend: signed-in acceptance, new-account registration, password sign-in, MFA sign-in, organization SSO, switching accounts and signing in again, refreshing during a pending MFA challenge, and required MFA enrollment in a second tab followed by returning and explicitly accepting without a page reload. Registration and sign-in assert the membership remains pending before acceptance. Page integration tests cover transient-load retries, organization-config retries, failed focus refreshes, and failed refreshes after logout. The scoped frontend suite has 39 passing tests; frontend type-checking and lint checks pass.