2012-02-16 20 views
1

私は、購入した製品を自分のウェブサイトに共有する機能を​​に追加しようとしています。これを行うには、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はそれから私が認証されていることを知っているので、私をリダイレクトしてループを引き起こします。

+0

あなたが提供したリンクは解決策を提示していません。 –

答えて

0

クッキーをまったく使用しないhttp://aka.ms/need01で利用可能なサンプルコードをいくつか作成しました。基本的には、私が書いたカスタム認証モジュール(Windows Azureテーブルに保存されたセッション状態で、別のストアを使用するセッション状態を使用して)を作成し、残りの状態をURLに格納します。 ほしいと思っています。