我試圖添加使用分享您剛剛購買到我的網站的產品的功能。爲此,您需要使用Facebook對用戶進行身份驗證並獲得所需的權限。Facebook身份驗證重定向循環
我有一些代碼檢查您是否經過身份驗證,如果沒有,將您重定向到Facebook oAuth頁面進行身份驗證。
然而,當從Facebook頁面返回時,它會進入一個重定向循環:
var auth = new FacebookWebAuthorizer();
bool authorized = auth.FacebookWebRequest.IsAuthorized(new string[] { "publish_stream" });
if (authorized)
{
var client = new FacebookClient(auth.FacebookWebRequest.AccessToken);
Dictionary<string, object> args = new Dictionary<string, object>();
args["message"] = "This is a test.";
args["name"] = "";
args["link"] = "http://www.example.com/";
args["description"] = "Test link.";
client.Post("/me/feed", args);
}
else
{
var facebookClient = new FacebookOAuthClient();
var parameters = new Dictionary<string, object> {
{ "redirect_uri", "http://www.example.com/" },
{ "client_id", "xxxx" },
{ "scope", "publish_stream" }
};
Response.Redirect(facebookClient.GetLoginUrl(parameters).ToString(), true);
}
我的web.config文件看起來是這樣的:
<configuration>
<configSections>
<section name="facebookSettings" type="Facebook.FacebookConfigurationSection" />
</configSections>
<system.web>
<customErrors mode="Off" />
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
<handlers>
<add name="facebookredirect.axd" verb="*" path="facebookredirect.axd" type="Facebook.Web.FacebookAppRedirectHttpHandler, Facebook.Web" />
</handlers>
</system.webServer>
<facebookSettings appId="xxxx" appSecret="xxxx" />
</configuration>
它看起來像我的網站是不是認識到我已經過身份驗證,因此它重定向到Facebook登錄。 Facebook然後知道我是通過身份驗證的,所以它重定向我,導致循環。
您提供的鏈接不提供解決方案,只是對問題的描述? – 2012-02-16 14:31:55