python-social-auth and github, I have this error “The redirect_uri MUST match the registered callback URL for this application”

不羁的心 提交于 2019-12-11 07:37:52

问题


I'm using python-social-auth on a project to authenticate the user with Github. I need to redirect the user depending on the link they use. To do that I'm using the next attribute on the url, and I didn't declare any redirect url on my github app neither in my django settings.

This is the href attribute I'm using for my link : {% url 'social:begin' 'github' %}?next={% url 'apply' j.slug %}

And the first time I click on it, I'm getting redirected to my homepage with this error in the url field : http://127.0.0.1:8000/?error=redirect_uri_mismatch&error_description=The+redirect_uri+MUST+match+the+registered+callback+URL+for+this+application.&error_uri=https%3A%2F%2Fdeveloper.github.com%2Fv3%2Foauth%2F%23redirect-uri-mismatch&state=Ui1EOKTHDhOkNJESI5RTjOCDEIdfFunt

But after first time the link work.

I don't know where is the problem, I hope someone can help me. Thanks


回答1:


This library uses OAuth for GitHub authentication.

You must provide a callback URL, because the OAuth process causes the user's browser to actually leave your site as part of the authentication process. The callback URL that you send to GitHub is used to redirect users back to your site.

It looks like Python Social Auth handles some of this for you, though (emphasis mine):

GitHub

Github works similar to Facebook (OAuth).

  • Register a new application at GitHub Developers, set the callback URL to http://example.com/complete/github/ replacing example.com with your domain.

  • Fill App Id and App Secret values in the settings:

    SOCIAL_AUTH_GITHUB_KEY = ''
    SOCIAL_AUTH_GITHUB_SECRET = ''
    
  • Also it’s possible to define extra permissions with:

    SOCIAL_AUTH_GITHUB_SCOPE = [...]
    

The tricky bit is getting this to work on your development machine.

Setting your domain to 127.0.0.1 in your hosts file should work, something like this

127.0.0.1   example.com

but make sure to comment this like out once you move into production!

You may also want to browse GitHub's OAuth documentation. Using a library is great, but if you understand the underlying technology you'll have fewer problems.




回答2:


that worked

Setting your domain to 127.0.0.1 in your hosts file should work, something like this

127.0.0.1 example.com



来源:https://stackoverflow.com/questions/23360160/python-social-auth-and-github-i-have-this-error-the-redirect-uri-must-match-th

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!