Skip to content

Allow to fill missing custom fields during Omniauth registration - #24652

Merged
NobodysNightmare merged 3 commits into
devfrom
omniauth-register-custom-fields
Aug 10, 2026
Merged

Allow to fill missing custom fields during Omniauth registration#24652
NobodysNightmare merged 3 commits into
devfrom
omniauth-register-custom-fields

Conversation

@NobodysNightmare

Copy link
Copy Markdown
Contributor

This PR solves several issues around registering users via Omniauth when their information is not yet complete. We explicitly did want to support this (see methods such as render_omniauth_registration_form), but lost the ability to do so long ago.

This should now be working again.

Ticket

https://community.openproject.org/wp/SI-235

@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown

Caution

The provided work package version does not match the core version

Details:

Please make sure that:

  • The work package version OR your pull request target branch is correct

@NobodysNightmare

Copy link
Copy Markdown
Contributor Author

Noteworthy mentions:

  • @bsatarnejad: I am reverting one line that you added very recently, see the last commit of this PR. I didn't notice this during review, but the explicit consent check broke the omniauth registration flow. Nobody would've noticed this before, because the form was unusable anyways and also didn't change appearance
  • @oliverguenther: You were the one to initially introduce the OmniauthService, which is when the submission of custom fields broke
    • passing this by you for a historic pair of eyes

P.S.: If anyone has a clue on how we could properly add tests for this case, I think we sourly need that xD

@NobodysNightmare NobodysNightmare changed the title Omniauth register custom fields Allow to fill missing custom fields during Omniauth registration Aug 7, 2026
@NobodysNightmare
NobodysNightmare force-pushed the omniauth-register-custom-fields branch from c2c886f to e420bf4 Compare August 7, 2026 07:59
@NobodysNightmare

Copy link
Copy Markdown
Contributor Author

P.S.: If anyone has a clue on how we could properly add tests for this case, I think we sourly need that xD

I think the failing spec pointed me to where I can add this missing spec... working on it ^^

@NobodysNightmare
NobodysNightmare force-pushed the omniauth-register-custom-fields branch 2 times, most recently from d47dde9 to 1801be3 Compare August 7, 2026 09:00

@oliverguenther oliverguenther left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Changes and specs LGTM.

With the consent no longer happening in that page, we can remove AccountController#self_registration!:379 as that's dead code if I'm not mistaken.

@NobodysNightmare

NobodysNightmare commented Aug 7, 2026

Copy link
Copy Markdown
Contributor Author

With the consent no longer happening in that page, we can remove AccountController#self_registration!:379 as that's dead code if I'm not mistaken.

Not quite sure. I can still see calls to self_registration!. If that's dead code, it's not dead due to this PR alone, since I am only removing one of many calls to consent_given_for_registration?(user)

I definitely think that more cleanup could be put into all of this. For example I still need to figure out how @user (prepared in AccountController) and user (as returned from the OmniauthService relate to each other. As far as I can tell, they were the same entity before the extraction of OmniauthService, but nowadays they are separated. So probably the one from AccountController is not needed at all in some cases?

@bsatarnejad bsatarnejad left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM!
the removed inline consent check is safe because consent is still enforced by :consent auth stage: config/initializers/authentication_stages.rb, so no bypass.

One small cleanup on the now-dead user.assign_attributes, otherwise ready. 👍

@@ -72,9 +72,7 @@ def register_with_auth_source(user) # rubocop:disable Metrics/AbcSize
# on-the-fly registration via omniauth or via auth source
if pending_omniauth_registration?
user.assign_attributes permitted_params.user_register_via_omniauth

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

assign_attributes looks dead now. We used to need it to build user.attributes for register_via_omniauth, but we now pass permitted_params.user_register_via_omniauth directly . Can we drop this line?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It probably is dead, but I have to admit that I didn't dare touching it. As written above, this user here is passed down from the AccountController and I am not entirely sure whether anyone is depending on side effects of that assignment still.

I'd like to push that cleanup out into a future PR.

Comment thread app/models/user.rb
# Is the user authenticated via an external authentication source via OmniAuth?
def uses_external_authentication?
user_auth_provider_links.exists?
user_auth_provider_links.any?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Worth a short comment explaining why this must be any? and not exists?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

When signing up through Omniauth we don't need to show password fields
and the possibility to register through other auth providers (we already
have one). The use of `exists?` mandated that the check was performed via
a database lookup before, which doesn't work for unpersisted users that don't
have corresponding database entries yet, but that do have unpersisted association
records already. Therefore `any?` works when `exists?` doesn't.
The params contain more than merely the attributes of the user record.
Most notably, they also contain custom fields, which are associated to
the user afterwards, but are not immediately part of the attributes.

This makes it possible to:

1. Login through Omniauth
2. During registration have validation errors for required custom fields
3. Fill out missing custom fields
4. Register successfully (still being an Omniauth user)
This was added very recently to improve rendering of consent errors
in all registration flows. However, for the omniauth case it kicked
us out of the flow that would end up in `render_omniauth_registration_form`.

Thus a failed consent would switch from the omniauth registration form
(that has no password and auth provider inputs, but connects the resulting
user to their original auth provider) to the regular registration form.

By removing this check, confirming the consent during the registration form
is not required anymore. This is at least consistent with remaining omniauth
behaviour. Lacking a required field, the user would be created first and then
asked to confirm the consent in a separate step. This is what happens now as well.

Caveat: Even if the consent is confirmed during the registration form, the second
step will pop up anyways. This issue exists regardless of keeping or removing this
check and is one more thing we need to fix about omniauth registrations.
@NobodysNightmare
NobodysNightmare force-pushed the omniauth-register-custom-fields branch from 1801be3 to e54f9d1 Compare August 7, 2026 14:23

@shiroginne shiroginne left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

:shipit:

@NobodysNightmare
NobodysNightmare merged commit d061dd8 into dev Aug 10, 2026
14 checks passed
@NobodysNightmare
NobodysNightmare deleted the omniauth-register-custom-fields branch August 10, 2026 06:08
@github-actions github-actions Bot locked and limited conversation to collaborators Aug 10, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Development

Successfully merging this pull request may close these issues.

4 participants