python-social-auth和github,我有这个错误“redirect_uri必须匹配这个应用程序的注册回调URL” [英] python-social-auth and github, I have this error "The redirect_uri MUST match the registered callback URL for this application"

查看:892
本文介绍了python-social-auth和github,我有这个错误“redirect_uri必须匹配这个应用程序的注册回调URL”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个项目上使用python-social-auth来用Github验证用户。
我需要根据用户使用的链接重定向用户。为此,我使用了url上的下一个属性,并且我没有在我的django设置中声明任何重定向url。



这是我用于链接的href属性: {%url'social:begin''github'%}?next = {%url'apply'j.slug%}



第一次点击它时,我在url字段中发现了这个错误,并重定向到了我的主页: 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



但第一次链接工作后。



我不知道问题在哪里,我希望有人能帮助我。谢谢

解决方案

这个库使用 OAuth



您必须提供回调网址,因为OAuth进程会导致用户的浏览器实际上离开您的网站作为身份验证过程的一部分。您发送给GitHub的回调URL用于将用户重定向到您的网站。



它看起来像Python Social Auth 为你处理一些这样的事情,尽管(强调我的):


GitHub



Github与Facebook类似(OAuth)。


  • GitHub开发人员注册新应用程序,将回调URL设置为 http://example.com/complete/github/ 替换 example.com with your domain

  • 应用程序密码设置值:

      SOCIAL_AUTH_GITHUB_KEY =''
    SOCIAL_AUTH_GITHUB_SECRET =''


  • 也可以使用以下方式定义额外的权限:

      SOCIAL_AUTH_GITHUB_SCOPE = [...] 



这个棘手的问题是让你的开发机器能够使用它。



在您的 hosts文件中将您的域设置为127.0.0.1应该可以工作,像这样

  127.0.0.1 example.com 

但是一旦你投入生产,一定要评论这一点!



你可能还想浏览 GitHub的OAuth文档。使用库很不错,但是如果你了解底层技术,那么问题会更少。

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

解决方案

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.

这篇关于python-social-auth和github,我有这个错误“redirect_uri必须匹配这个应用程序的注册回调URL”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆