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

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!

2 Likes

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

3 Likes

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.

2 Likes