OAuth.io连接失败

OAuth.io connection failed

本文关键字:失败 连接 io OAuth      更新时间:2023-09-26

我是web编程的新手,我尝试在我的web应用程序中使用oauth.io。由于指示,我完成了对facebook和谷歌的配置。当我在他们的网站上测试配置时,一切都很好。然而,当我尝试实现到我的web应用程序时,OAuth不会连接到提供者。

我在html中加载了oauth.js,在html中创建了一个按钮,并使用onclick="pop"调用javascript中的函数。在javascript中的pop()函数中,我添加了:

OAuth.initialize('the-public-key-in-my-acc");
OAuth.popup('facebook', function(err, res) { if (err) { alert(something)});

然后我点击按钮。一个弹出窗口突然出现并立即关闭。我还尝试使用OAuth.redirect并将其重定向到http://oauth-io.github.io/oauth-js或者我的本地主机,但它说连接失败。

执行过程中是否遗漏/出错?

非常感谢你的帮助。

PS:我正在使用localhost,并尝试将重定向url设置为localhost:portnr。但仍然失败(

这是我写的示例代码:

Html:

<div><button onclick="oauthPop()">Try OAuth-io</button></div>

JS:

var oauthPop = function() {
OAuth.initialize('my-pub-key-on-authio');
OAuth.popup('facebook', function(err, res) { // or OAuth.callback
    // handle error with err
    if (err) {
        alert ("error")
    } else {
        // get my name from fb
        res.get('/me').done(function(data) {
            alert(data.name)
        })
    }});
}

OAuth.io需要加载jQuery才能使用OAuth.popup()的结果发出HTTP请求。它在后台使用jQuery.ajax(),为您提供一个众所周知的函数,其中包含您可能需要的所有选项。