2

I am writing a web application using server-side authentication, and I've been trying to figure out a way to leverage Facebook's Javascript SDK in my application.

The documentation for FB.init defines the optional authResponse parameter as something used to "Manually set the object retrievable from getAuthResponse". It also states that once obtained, an application may store the entire authResponse object for future access. This may work if an application uses FB.login, the Javascript SDK's authentication, but what about an app using server-side authentication?

Server-side authentication enables my app to obtain a user's access token, the most crucial piece of information needed for graph API calls. I would hope that this access_token alone would be enough to construct a valid authResponse object to use to authenticate to use with the Javascript SDK.

Merely calling FB.init (with valid appID, channelUrl, and other parameters) with an authResponse containing a valid "accessToken" field is not sufficient. Including the userId is also insufficient. Ideally, these parameters alone would work. The only others defined for the authResponse are 'expiresIn' and 'signedRequest'. Which, if either, of these parameters would be sufficient to generate a valid authResponse object? To what values must they be assigned?

I managed to dig up this description of a 'signedRequest': https://developers.facebook.com/docs/authentication/signed_request/

This document raises a number of questions. I assume that the signature is produced by a symmetric algorithm. If not, then generating it would not be possible. Assuming it is possible, the description of the payload is in no way specific. There is a list of 9 parameters, none of which are labeled as required.

4

2 に答える 2

0

CBroe が言うように、手動で何かを渡すべきではありません。FB.getLoginStatusへの呼び出しから開始し、javascript ハンドラーを引数としてこのメ​​ソッドに渡します。getLoginStatus 呼び出しから authResponse が返されます。

もちろん、理論上は、/me?access_token=blah_blah などの任意の FB.api 呼び出しに access_token パラメータを渡すことができます。ここで、blah_blah は使用している文字列ですが、これは必須ではなく、これを応答ハンドラ。

アクセス トークンの生成/拡張/検証に JavaScript SDK とサーバー側認証を使用する場合は、十分に注意してください。2 つの別々のコード パスを維持することになり、Facebook に対して同じ呼び出しを何度も行うことになります。アクセス トークンを自分の側に保存している場合でも、サーバー側でアクセス トークンを取得し、クライアント側で FB.api を呼び出してアクセスを使用するよりも、最適なアプローチを 1 つ選択することをお勧めします。トークン。

于 2012-07-17T12:37:07.300 に答える