question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

what is the correct way to use oauth2 with forwarded domains

See original GitHub issue

We’re using a domain-forwarded setup in which the code itself runs on project-plus-random-prefix.ourstagingserver.org but this code is accessed through project-staging.ourserver.org (which acts as router for a number of different requests, one set of those being django routes, others being completely different things). When using Google Auth (oauth2) we can’t seem to point the google callback to project-staging.ourserver.org/soc/complete/google-oauth2 because the redirect_url that the social auth library adds into the login is for project-plus-random-prefix.ourstagingserver.org, and I cannot seem to find anything in the docs that explain how to tell social auth what the actual redirect uri should be.

I did find SOCIAL_AUTH_LOGIN_REDIRECT_URL in http://python-social-auth-docs.readthedocs.io/en/latest/configuration/settings.html#urls-options but this documentation seems to suggest this is a path rather than a full URL, so if this value can be used for a fully qualified URL, can the docs be updated to explicitly mention that? And if not, what is the correct way to make sure social-auth uses the domain that it needs to be using for auth to succeed?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
omabcommented, May 10, 2017

@Pomax, @cadecairos, python-social-auth uses Django build_absolute_uri helper that’s in the HTTP Request class, looking at the code, you can see that it uses get_host() method defined a few lines above, this one uses _get_raw_host(), which will attempt to determine the host based on settings and/or request headers.

The common use case is to make the front server, load-balancer, proxy, etc, set the X-Forwarded-Host header with the domain, but to make it work with Django, ensure that the setting USE_X_FORWARDED_HOST is set to True.

More details on thins can be found in Django docs.

0reactions
Pomaxcommented, May 11, 2017

I’ll echo that: thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Redirect URLs - OAuth 2.0 Simplified
The best way to ensure the user will only be redirected to appropriate locations is to require the developer to register one or...
Read more >
Using OAuth 2.0 for Web Server Applications | Authorization
The following steps show how your application interacts with Google's OAuth 2.0 server to obtain a user's consent to perform an API request...
Read more >
Redirect to Another Domain · Issue #216 · oauth2-proxy ...
When trying to get this working, I am being redirected to https://oauth.domain.com, instead of https://myapp.domain.com. I have the following ...
Read more >
An Introduction to OAuth 2 - DigitalOcean
This informational guide is geared towards application developers, and provides an overview of OAuth 2 roles, authorization grant types, ...
Read more >
OAuth 2.0 explained - Connect2id
3. How can a client obtain a token? ... In order to obtain an access token the client needs to present a valid...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found