0

在此处的身份验证流程文档中,它提到了在 oAuth 身份验证时返回的 CODE。

这是 Javascript SDK 所必需的,还是在此代码的后台自动处理?

通过“这是必需的吗?” 我的意思是,我是否必须处理此代码来验证请求的真实性,或者 JavaScript SDK 是否自动使用该代码来获取access_token.

该文档解释了客户端流程,以及如何使用“代码”获取访问令牌,直到现在。我一直假设 SDK 在后台自动管理它,因为它生成的访问代码为response.authResponse.accessToken.

FB.login(function(response) {

    if (response.authResponse) {

        // User is logged in to Facebook and accepted permissions

        // Assign the variables required
        var access_token = response.authResponse.accessToken;
        var fb_uid = response.authResponse.userID;

        alert(dump(response.authResponse));

        // Construct data string to pass to create temporary session using PHP
        var fbDataString = "uid=" + fb_uid + "&access_token=" + access_token;
        // Call doLogin.php to log the user in
        $.ajax({
            type: "POST",
            url: "ajax/doLogin.php",
            data: fbDataString,
            dataType: "json",
            success: function(data) {

                // Get JSON response
                if (data.result == "failure")
                {
                    alert(data.error_message);

                    window.location.reload();

                    return false;
                }
                else if (data.result == "success")
                {
                    window.location.reload();

                    return true;
                }

            },
            error: function() {
                return false;
            }
        });

    } else {
        // user is not logged in and did not accept any permissions
        return false;
    }
}, {scope:'publish_stream,email'});

我想知道,因为我想确保我的代码是安全的。

4

1 回答 1

1

从文档

有了这段代码,您可以继续下一步,应用程序身份验证,以获取进行 API 调用所需的访问令牌。

为了验证您的应用程序,您必须将授权代码和您的应用程序密码传递给位于https://graph.facebook.com/oauth/access_token的 Graph API 令牌端点。应用程序机密可从开发人员应用程序中获得,不应与任何人共享或嵌入到您将分发的任何代码中(您应该在这些场景中使用客户端流程)。

如果您计划使用 FB.api 函数来调用他们的 Graph API,那么您需要获取访问令牌的代码。但是,如果您只需要对用户进行身份验证,那么您所拥有的就可以了。

于 2011-10-11T10:33:56.263 回答