【问题标题】:Facebook Server-side Authentication with Classic ASP使用经典 ASP 的 Facebook 服务器端身份验证
【发布时间】:2012-01-27 23:47:32
【问题描述】:

类似于this closed question,但我会让我的更精确,所以希望会有答案:)

我正在将 Facebook 登录按钮添加到一个全部采用经典 ASP 的网站,而且我是 Facebook SDK/API 的新手,并且 https://developers.facebook.com/docs/authentication 提供了它的所有代码示例在 PHP 中。我需要通过一些 COM 函数将一些 FB 用户信息传递给服务器的数据库,所以我将使用服务器端身份验证。到现在为止还挺好。服务器端身份验证没有直接给我 访问令牌,虽然它给了我一个 代码,我大部分了解 PHP 示例如何把它变成访问令牌,

$token_url = "https://graph.facebook.com/oauth/access_token?"
   . "client_id=" . $app_id . "&redirect_uri=" . urlencode($my_url)
   . "&client_secret=" . $app_secret . "&code=" . $code;
 $response = @file_get_contents($token_url);
 $params = null;
 parse_str($response, $params);
 $graph_url = "https://graph.facebook.com/me?access_token=" 
   . $params['access_token'];
 $user = json_decode(file_get_contents($graph_url));

我真的不知道用 ASP / VBScript 方法来完成上述任何操作。 PHP 提供了比 ASP 更多的内置函数,例如 urlencodefile_get_contentsparse_str,它们足够聪明,可以将字符串视为查询参数,我什至不知道我是否想要或需要类似的东西json_decode 与否!

对于 file_get_contents 我正在考虑尝试类似的东西

fbApiCode = Request.QueryString("code")
    if len(fbApiCode) > 0 then
        set xmlHttp = Server.CreateObject("Microsoft.XMLHTTP")
        appAuth = "https://graph.facebook.com/oauth/access_token?client_id=" & _
           Application("fbAppId") & "&redirect_uri=" & Application("fbRedirectUri") & "&client_secret=" _
           Application("fbAppSecret") & "&code=" & fbApiCode
        xmlHttp.open("GET", appAuth, false) ' or post?
        accessResponse = xmlHttp.responseText

这甚至接近正确的方法还是我跑进了兔子洞?如果我不能仅使用 VBScript 将代码转换为访问令牌,我将不得不使用 FB.getLoginStatus() 在 JavaScript 中获取 FB 用户的信息(姓名、电子邮件等),然后使用 AJAX 将其发送到我的服务器,这我知道这不是很安全,所以我想避免使用它。

【问题讨论】:

  • 这是什么类型的网络应用程序?页面标签应用程序?画布应用?一个独立的网站?
  • "人们还在使用经典的 ASP 吗?"是的。
  • 这可能对codeproject.com/Articles/94067/…有帮助
  • 独立网站,有自己的注册/登录,我需要与 Facebook 登录集成。允许新老用户使用 Facebook 登录确实是我们计划使用的唯一 Facebook API 功能。 (是的,这是很多遗留代码;直到现在,一些控制 reg/login 的代码自 2004 年以来不需要任何更改!)
  • @bkaid,看看窗外。那个地方叫做现实世界。在其中,人们不得不使用像经典 ASP 这样的旧技术。

标签: facebook asp-classic


【解决方案1】:

我知道这是一个旧线程,但这个解决方案可能会对某人有所帮助。

您需要使用代码请求令牌,然后使用令牌请求用户信息。

<script language="javascript" runat="server">
"use strict";
function getJSON(strOrObject){
    if (typeof strOrObject == "string") {
        return eval("(" + strOrObject + ")");
    }
    return strOrObject;
}
</script>
<%
fbClientToken = [[CLIENTTOKEN]]
fbAppID = [[APPID]]
fbAppSecret = [[APPSECRET]]

fbAuthURL = "https://www.facebook.com/dialog/oauth"
fbTokenURL = "https://graph.facebook.com/v2.3/oauth/access_token"
fbOAuthCallback = [[CALLBACKURL]]
fbScope = "public_profile,email"
if request("go")="login" then
    Randomize
    nonce = Rnd
    response.redirect fbAuthURL & "?response_type=code&client_id=" & fbAppID & "&redirect_uri=" & Server.URLEncode(fbOAuthCallback) & "&scope=" & fbScope & "&state=" & nonce
else
    if request("code") <> "" then       
        information = "client_id=" & fbAppID & "&redirect_uri=" & Server.URLEncode(fbOAuthCallback) & "&client_secret=" & fbAppSecret & "&code=" & request("code")
        Set xmlhttp = server.Createobject("MSXML2.ServerXMLHTTP")
        xmlhttp.Open "GET", fbTokenURL & "?" & information, false
        xmlhttp.setRequestHeader "Content-Type","application/x-www-form-urlencoded"
        xmlhttp.send        
        respText = xmlhttp.ResponseText     
        if InStr(respText,"access_token") then
            dim respJSON : set respJSON = getJSON(respText)
            getURL = "https://graph.facebook.com/me?access_token=" & respJSON.access_token
            xmlhttp.Open "GET", getURL, false
            xmlhttp.setRequestHeader "Content-Type","application/x-www-form-urlencoded"
            xmlhttp.send
            respToken = xmlhttp.ResponseText
            %><h1>Token Inspection Response</h1><%
            if InStr(respToken,"{") and InStr(respToken,"}") then
                dim userJSON : set userJSON = getJSON(respToken)
                response.write "<br/>ID: " & userJSON.id
                response.write "<br/>email: " & userJSON.email
                response.write "<br/>first_name: " & userJSON.first_name
                response.write "<br/>last_name: " & userJSON.last_name
                response.write "<br/>name: " & userJSON.name
                response.write "<br/>gender: " & userJSON.gender
                response.write "<br/>locale: " & userJSON.locale
                response.write "<br/>verified: " & userJSON.verified
                response.write "<br/>link: " & userJSON.link
                response.write "<br/>timezone: " & userJSON.timezone
            else
                %><h1>Invalid Inspection Response</h1><%=respToken%><%
            end if          
        else
            %><h1>Invalid Response</h1><%=respText%><%
        end if
    end if
end if
%>

【讨论】:

    猜你喜欢
    • 2010-12-02
    • 1970-01-01
    • 1970-01-01
    • 2012-05-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多