Skip to content

Conversation

@sandhose
Copy link
Member

@sandhose sandhose commented Nov 21, 2025

This can be reviewed commit by commit.

The intention of this is to unify how we register user, by using the UserRegistration abstraction for upstream OAuth registrations. I intended to do that when I introduced that in #3784 but didn't got around to do it.

The nice thing with this is that it gives us registration tokens support for upstream OAuth providers

Fixes #4980

This will let us push emails in user registrations using an upstream
session
This will allow us creating user registrations from upstream OAuth auth
sessions
In case an email is required for password auth, we create a user
authentication which we force the user to complete. We used to
double-check that the email is required before completing the
registration, which was only really useful when the config flipped from
not being required to being required, in the 1h window in which running
registrations were still valid. We think this is a fine trade-off.
@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Nov 21, 2025

Deploying matrix-authentication-service-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: 61ee8da
Status: ✅  Deploy successful!
Preview URL: https://54597060.matrix-authentication-service-docs.pages.dev
Branch Preview URL: https://quenting-upstream-user-regis.matrix-authentication-service-docs.pages.dev

View logs

@sandhose sandhose force-pushed the quenting/upstream-user-registration branch from 6fd1b7d to 1e69ea8 Compare November 24, 2025 15:52
@sandhose sandhose requested a review from Copilot November 24, 2025 15:52
Copilot finished reviewing on behalf of sandhose November 24, 2025 15:56
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR unifies the registration flow for local password-based registrations and upstream OAuth registrations by introducing support for storing upstream OAuth sessions on user registrations. This enables users to complete registrations that were initiated through OAuth providers, with optional email verification.

Key changes:

  • Added upstream_oauth_authorization_session_id field to user registrations
  • Split complete_authentication into two methods: complete_authentication_with_code and complete_authentication_with_upstream
  • Modified OAuth registration flow to create user registrations instead of directly creating users, allowing multi-step registration flows

Reviewed changes

Copilot reviewed 13 out of 14 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
crates/data-model/src/users.rs Added upstream_oauth_authorization_session_id field to UserRegistration struct
crates/storage/src/user/registration.rs Added trait method set_upstream_oauth_authorization_session for associating OAuth sessions with registrations
crates/storage/src/user/email.rs Renamed complete_authentication to complete_authentication_with_code and added complete_authentication_with_upstream method
crates/storage-pg/src/user/registration.rs Implemented set_upstream_oauth_authorization_session with database query and added comprehensive tests
crates/storage-pg/src/user/email.rs Implemented both authentication completion methods with appropriate database updates
crates/storage-pg/migrations/20251121145458_user_registration_upstream_oauth_session.sql Added database column and index for tracking upstream OAuth sessions in registrations
crates/handlers/src/views/register/steps/finish.rs Updated to handle upstream OAuth registrations, verify links aren't already associated, and authenticate users with upstream sessions
crates/handlers/src/upstream_oauth2/link.rs Refactored OAuth registration to use the registration flow instead of directly creating users, enabling multi-step registrations
crates/handlers/src/views/register/mod.rs Exported UserRegistrationSessionsCookie for use in OAuth link handler
crates/handlers/src/views/register/steps/verify_email.rs Updated to use renamed complete_authentication_with_code method
crates/handlers/src/graphql/mutations/user_email.rs Updated to use renamed complete_authentication_with_code method
crates/storage-pg/src/user/tests.rs Updated test cases to use renamed complete_authentication_with_code method
crates/storage-pg/.sqlx/query-*.json Updated SQLx query metadata files to reflect new database schema
Files not reviewed (1)
  • crates/storage-pg/.sqlx/query-4c37988dacca5a83c8b64209042d5f1a8ec44ec8ccccad2d7fce9ac855209883.json: Language not supported

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@sandhose sandhose marked this pull request as ready for review November 24, 2025 16:00
@sandhose sandhose requested a review from a team as a code owner November 24, 2025 16:00
code: &UserEmailAuthenticationCode,
) -> Result<UserEmailAuthentication, Self::Error>;

/// Complete a [`UserEmailAuthentication`] by using the given upstream oauth
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this saying that we accept e.g. Apple's claim of a user's email address instead of them actually verifying their email directly with us?

Maybe this doc would be a bit better if it said the circumstances in which you can do this, but maybe something I'll see in later commits.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already assumed that. In the past, we've let the admin choose in the configuration whether to trust it or not, but this lead to more confusion than anything

Comment on lines 12 to 13
CREATE INDEX user_registrations_upstream_oauth_session_id_idx
ON user_registrations (upstream_oauth_authorization_session_id);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is user_registrations small enough that we're happy to do this non-CONCURRENTLY?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might, but that's a good point! Fixed in 4c3d2ba

}

#[sqlx::test(migrator = "crate::MIGRATOR")]
async fn test_set_upstream_oauth_link(pool: PgPool) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe _link is a slight misnomer / not consistent with the other methods

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a leftover for when it was the link that was attached to registrations, not the session! Fixed in 61ee8da

@sandhose sandhose enabled auto-merge November 27, 2025 15:05
@sandhose sandhose merged commit 4b6c1db into main Nov 27, 2025
17 checks passed
@sandhose sandhose deleted the quenting/upstream-user-registration branch November 27, 2025 15:13
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.

Require registration tokens when registering via OAuth provider

3 participants