[PAID] Extend the OAuth2 Basic Plugin

AI-generated summary

andyh is seeking to extend the Discourse Oauth2 Basic plugin to enhance SSO functionality for their site, with potential broader utility. Currently, the plugin only fetches user data (email, UUID, etc.) from the oauth2_user_json_url endpoint during account creation. The requested enhancements include: (1) adding support for an email_verified boolean field in the API response to indicate whether the user’s email has been confirmed at the OAuth2 provider; and (2) enabling ongoing checks of the oauth2_user_json_url endpoint after sign-up for three key purposes: to delay account activation until email is verified (with a “refresh” link for users), to sync updated user data (like email) or deactivate accounts upon login if the API returns 401, and optionally to periodically poll the API to detect account deactivation even if the user doesn’t log back in. Additional admin controls would be needed, such as preventing local email changes in Discourse and redirecting users to the OAuth2 provider’s email update page. These changes aim to improve account synchronization and security between Discourse and the OAuth2 provider.

We’re using the Discourse Oauth2 Basic plugin to do SSO via our API, we’d like to add functionality and we think it might be useful to other sites too.

Context:
During the account create process, once an OAuth2 token is obtained the plugin retrieves account data like email and uuid from an API endpoint oauth2_user_json_url the admin specifies in Discourse.

As far as I can tell though, the oauth2_user_json_url endpoint is only contacted once during sign-up.

Features Requested:

  • Add a user data attribute to pull from oauth2_user_json_url: email_verified - Admins tell the plugin where to look for email, full name, user id, username and avatar in the oauth2_user_json_url response, we’d like to also specify an email_verified boolean field meant to indicate whether a user has confirmed their account at the OAuth2 provider.

  • Add option to continue to check oauth2_user_json_url after sign-up
    Here are three scenarios where this would be useful:

    • Check if Email is Verified - Keep the Discourse account unactivated until Discourse receives an email_verified=true response from the API. Show the user a pending state with a “refresh” link that re-checks.
    • Check for updated user email, account state upon login - When a user logs in via the OAuth2 Provider, re-contact the oauth2_user_json_url endpoint and update their Discourse email address if it has changed at the provider, and deactivate their account if the API returns a 401 response.
    • Check API periodically for email, account state updates - I am least sure about this one, but I want to solve the problem where a user deactivates their account at the OAuth2 Provider, and doesn’t log back in to Discourse. In that case we still want Discourse to (eventually) get the news that the user is inactive, which could happen via a 401

There are a couple other admin options that would be required along with this, like preventing a user from changing their email in Discourse and allowing admins to specify a URL to send users to where they can change their email at the OAuth2 provider.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.