Skip to content
This repository was archived by the owner on Jul 14, 2025. It is now read-only.

Conversation

@nattsw
Copy link
Contributor

@nattsw nattsw commented Jan 31, 2024

When retrieving userinfo with oauth2_fetch_user_details=true, we sometimes want to disallow account creation if an attribute is not fulfilled.

This PR adds a new register oauth2_basic_required_json_path which will kick in when retrieving userinfo. It can be used this way:

DiscoursePluginRegistry.register_oauth2_basic_required_json_path({
      path: "extra:account.is_allowed_member",
      required_value: true,
      error_message: I18n.t("login.unfulfilled_requirement"),
    }, self)

If the attribute does not satisfy the required value, we will see the specified error message when returning to the forum. The account is not created.

Screenshot 2024-01-31 at 12 45 44 PM

Alternatives

The alternatives I can think of is

  1. monkey patching
  2. creating a new authenticator

(1) is definitely brittle, and (2) does feel like there will be a lot of copy-work even within the method itself.

  1. David did point out on(:after_auth) exists. However the event happens slightly too late - the associated account would have been created already, and the result would not contain the required attribute.

@nattsw nattsw requested a review from davidtaylorhq January 31, 2024 10:37
@nattsw nattsw force-pushed the oauth-required-path branch from 5d3f769 to 9f147e9 Compare January 31, 2024 11:59
@nattsw nattsw force-pushed the oauth-required-path branch from 9f147e9 to 0213d12 Compare January 31, 2024 12:13
@nattsw nattsw merged commit 895db12 into main Jan 31, 2024
@nattsw nattsw deleted the oauth-required-path branch January 31, 2024 12:19
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.

3 participants