Login flow (Flask -> Discourse -> Flask) with OAuth

AI-generated summary

The user is attempting to integrate OAuth login functionality between a Flask app and a Discourse instance. They have two scenarios:

  1. User signs up for a Discourse account via OAuth and wants to be redirected back to the Flask app’s /home page after completing registration.
  2. User signs in to the Flask app using their existing Discourse account via OAuth and wants to be redirected to the /user page after verification.

nix is seeking an optional callback_url parameter that would allow Discourse to redirect the user to the specified URL after OAuth verification. This would enable the Discourse instance to act as an OAuth provider for the Flask app. rishabh suggested checking the Discourse documentation, but nix found that it does not cover their specific use case.

Hi there!

I have two questions that are related, hopefully someone can help :slight_smile:

I’ve configured my Discourse instance to support OAuth via Twitter, Facebook, and Google. What I’m looking to do is the following:

Scenario 1:

  1. User lands on /home (Python/Flask app)
  2. They want to sign up for a Discourse account.
  3. They get redirected to the appropriate OAuth flow, e.g. https://discourse.example.com/auth/google.
  4. Can I redirect them back to /home once they complete their registration?

Scenario 2:

  1. User lands on /home (Python/Flask app)
  2. They already have a Discourse account.
  3. They want to sign in on the main app using OAuth in order to access some protected page.
  4. They get redirected to the appropriate OAuth flow.
  5. Can I redirect them to /user once Discourse has verified their account credentials?

Please let me know if anything is unclear and I will be happy to elaborate!

Thanks!

Just in case you haven’t seen it yet, our documentation is at Discourse OAuth2 Basic. Does that have some of the answers you’re looking for?

Thanks for the reply @rishabh!

Unfortunately as far as I can tell the documentation doesn’t cover my questions. My OAuth configurations are working as expected, it’s only the additional functionality outlined in scenarios 1 & 2 that cause trouble.

What I’m looking for is something along the lines of an optional parameter, callback_url, that would redirect the user to its target URL, after the OAuth provider has verified their account, and returned them to Discourse.

I guess it’s sort of as if my Discourse instance acted as an OAuth provider in and of itself, for my Flask/Python app?

E.g. https://discourse.example.com/auth/google?callback_url=https://example.com/home takes the user to Google, returns them to Discourse, which in turn redirects them to callback_url.