gpt4 book ai didi

javascript - 如何在我的网络应用程序中集成 github 登录 (JavaScript)

转载 作者:行者123 更新时间:2023-11-30 14:28:19 25 4
gpt4 key购买 nike

<分区>

我想让用户使用 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');
}

});

如何纠正此问题以便我可以集成登录?

编辑:我不能使用网守之类的外部应用程序。这是一个测试网站,但最终将用于公司网站。

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com