Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Force https redirect_uri causes Exception when loading strategy #148

Closed
roberto-robles opened this issue Jan 8, 2014 · 3 comments
Closed

Comments

@roberto-robles
Copy link
Contributor

Hi,

First I wanna thank you for such great job with this project, it has been a real help for me. I have been using python-social-auth for a couple of months in my django project, and I realized that if I am setting up a redirect_uri with https in my Google app for google-oauth2 auth it was automatically changed to a uri with http, so I dive into this. And realized of the following:

On your documentation you said that we must set in settings.py:

SOCIAL_AUTH_REDIRECT_IS_HTTPS = True

So all redirects uses https, for some reason this setting is not being used, instead if you go into social.strategies.base you can see on line 188 the following code for the function absolute_uri:

uri = self.build_absolute_uri(path)
if self.setting('ON_HTTPS'):
uri = uri.replace('http://', 'https://')
return uri

I couldn't find any information on your documentation regarding that ON_HTTPS setting, so I added it, and it solved the first problem with the redirect_uri with https.

But after that If for some reason I need to execute again on my Django app a load_strategy function, it raises an Exception telling me that None object has replace function. So I come to the following fix that at least on my case and using many API social providers works perfectly for me:

replace on social.strategies.base.py
def absolute_uri(self, path=None):
uri = self.build_absolute_uri(path)
if self.setting('ON_HTTPS'):
uri = uri.replace('http://', 'https://')
return uri

with this:

def absolute_uri(self, path=None):
    uri = self.build_absolute_uri(path)
    if uri and self.setting('SOCIAL_AUTH_REDIRECT_IS_HTTPS'):
        uri = uri.replace('http://', 'https://')
    return uri

Please tell me If I am missing something on this problem and should avoid this patch for my problem.

PD: Sorry for my bad english.

Thanks!

@omab
Copy link
Owner

omab commented Jan 9, 2014

@roberto-robles, the PR looks good but I've left a comment on it, thanks for spotting the issue, if you do that little change I'll merge it.

@omab
Copy link
Owner

omab commented Jan 9, 2014

PR merged, thanks!

@omab omab closed this as completed Jan 9, 2014
@gameguy43
Copy link
Contributor

Thanks for this thread and for patching--solved my problem!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants