作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
<分区>
我想让用户使用 github 登录我的网络应用程序(之后我可以使用他们的姓名/电子邮件等),就像您使用 Google 或 Facebook 登录 stackoverflow 一样。我知道您必须将用户带到 github 登录,一旦他们验证了您的应用程序,您就可以从用户重定向到的页面的 url 中检索代码,并使用该代码发出 POST 请求以获取访问权限代码,您可以使用它来访问 github API。但是,当我对访问代码发出 POST 请求时,出现 CORS 错误:
Failed to load https://github.com/login/oauth/access_token?client_id=7...&client_secret=b...&code=f...: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost' is therefore not allowed access.
响应的 HTTP 状态代码为 404。
这是我的 POST 请求:
$.ajax (
{
url:"https://github.com/login/oauth/access_token?client_id=7...&client_secret=b...&code=" + authCode, // Extraction of authCode has no bugs
type:'POST',
dataType:'json',
success: function() {
alert('success');
},
error: function() {
alert('error');
}
});
如何纠正此问题以便我可以集成登录?
编辑:我不能使用网守之类的外部应用程序。这是一个测试网站,但最终将用于公司网站。
我是一名优秀的程序员,十分优秀!