【问题标题】:what should be implemented in the facebook redirect uri?在 facebook 重定向 uri 中应该实现什么?
【发布时间】:2016-03-23 02:31:19
【问题描述】:

我有一个 Angular 1.5.0-rc0 应用程序,带有 satellizer,以便登录 facebook。

网站连接到https://myalcoholist.com:8888的nodejs服务器

网址是https://myalcoholist.com

要使用 facebook 配置 satellizer,我有以下代码:

app.config(function($authProvider) {

        $authProvider.facebook({
            clientId: '226393057557099',
            url: 'https://myalcoholist.com:8888/auth/facebook',
            redirectUri: 'https://myalcoholist.com'
        });
    });

和我的角度登录控制器代码:

(function () {
angular.module('myalcoholist').controller('LoginController',['$scope','$auth','$location', 'toastr',function ($scope,$auth,$location,toastr) {
    $scope.authenticate = function (provider) {
        $auth.authenticate(provider).then(function () {
                toastr.success('You have successfully signed in with ' + provider + '!');
                $location.path('/');
            })
            .catch(function (error) {
                    if (error.error) {
                        // Popup error - invalid redirect_uri, pressed cancel button, etc.
                        toastr.error(error.error);
                    } else if (error.data) {
                        toastr.error(error.data.message, error.status);
                    } else {
                        toastr.error(error);
                    }
                }
            )
    }
}]);
})();

我的 nodejs 应用程序使用 restify 框架来处理请求 我将其配置为路由:

server.post('/auth/:provider', function (req,res,next) {
    require(post_commands_dir + 'auth.js')(req,res,next);
})

并且 auth.js 包含

var FB = require('fb');

function auth(req, res, next) {
var clientId = req.params.clientId;
var code = req.params.code;
var provider = req.params.provider;

FB.api('oauth/access_token', {
    client_id: '<CLIENT_ID>',
    client_secret: '<CLIENT_SECRET>',
    redirect_uri: 'https://myalcoholist.com',
    code: code
}, function (response) {
    if(!response || response.error) {
        console.log(!response ? 'error occurred' : response.error);
        return;
    }

    var accessToken = response.access_token;
    res.send(JSON.stringify({token:accessToken}));
 //       var expires = response.expires ? response.expires : 0;
});
}

module.exports = auth;

在视图中的 Angular 项目中,我有一个按钮,用于调用我添加到范围中的身份验证函数。当我点击登录时,它会打开一个 facebook 弹出窗口,然后我点击允许,然后它会关闭弹出窗口并在后台使用代码执行对 https://myalcoholist.com:8888/auth/facebook 的发布请求。当我尝试使用auth.js 中的代码将代码转换为访问令牌时,出现以下错误:

{ message: 'Error validating verification code. Please make sure your redirect_uri is identical to the one you used in the OAuth dialog request',
type: 'OAuthException',
code: 100,
fbtrace_id: 'B09qSPJS08d' }

现在在 facebook 控制台中,我将 Valid OAuth redirect URIs 配置为 https://myalcoholist.com

现在我认为我可能误解了 redirect_uri,我应该以不同的方式实现它。我只是不知道怎么做。有什么想法吗?

【问题讨论】:

  • 什么在您的登录对话框调用中使用的重定向 URI?
  • @CBroe 我将其配置为myalcoholist.com
  • 这是登录对话框URL中参数的实际值吗?
  • @CBroe - 感谢您的帮助。我找到了解决方案。

标签: angularjs node.js facebook restify satellizer


【解决方案1】:

在 facebook 应用程序开发人员控制台中,当我将 https://myalcoholist.com 添加到 OAuth 回调 URL 时,它会自动将 / 添加到它。这就是我在我的 API 服务器中所缺少的。 api服务器中的redirect_url配置为https://myalcoholist.com,没有结尾/

welp 问题已解决。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-19
    • 2019-03-21
    • 1970-01-01
    • 2018-08-01
    • 2020-02-29
    相关资源
    最近更新 更多