3

カスタムSTSでWindowsAzureアクセス制御サービスを使用しています。ACSからアプリケーションにログインできますが、ログアウト機能に問題があります。私は自分のアプリケーションでこのコードを試しました。

        WSFederationAuthenticationModule fam = FederatedAuthentication.WSFederationAuthenticationModule;

        try
        {
            FormsAuthentication.SignOut();
        }
        finally
        {
            fam.SignOut(true);
        }
        Page.Response.Redirect("default.aspx");

ただし、ACSからはログアウトしますが、カスタムSTSからはログアウトしないようです。STSからログアウトするにはどうすればよいですか。アプリケーション(RP)、ACS、またはSTSのどこに問題があるのでしょうか。

ACSはカスタムSTSにユーザーのログアウトを要求する必要があると思いますが、そうではないようです。私が欠けているものは何ですか?

4

2 に答える 2

5

FederatedSignout を実行するためのヘルパー メソッドを作成し、途中で発見したコードにコメントを付けました (hth)

public static void FederatedSignOut(string reply = null)
{
   WSFederationAuthenticationModule fam = FederatedAuthentication.WSFederationAuthenticationModule;

   // Native FederatedSignOut doesn't seem to have a way for finding/registering realm for singout, get it from the FAM
   string wrealm = string.Format("wtrealm={0}", fam.Realm);

   // Create basic url for signout (wreply is set by native FederatedSignOut)
   string signOutUrl = WSFederationAuthenticationModule.GetFederationPassiveSignOutUrl(fam.Issuer, null, wrealm);

   // Check where to return, if not set ACS will use Reply address configured for the RP
   string wreply = !string.IsNullOrEmpty(reply) ? reply : (!string.IsNullOrEmpty(fam.Reply) ? fam.Reply : null);

   WSFederationAuthenticationModule.FederatedSignOut(new Uri(signOutUrl), !string.IsNullOrEmpty(wreply) ? new Uri(wreply) : null);

   // Remarks! Native FederatedSignout has an option for setting signOutUrl to null, even if the documentation tells otherwise.
   // If set to null the method will search for signoutUrl in Session token, but I couldn't find any information about how to set this. Found some Sharepoint code that use this
   // Michele Leroux Bustamante had a code example (from 2010) that also uses this form.
   // Other examples creates the signout url manually and calls redirect.

   // FAM has support for wsignoutcleanup1.0 right out of the box, there is no need for code to handle this.
   // That makes it even harder to understand why there are no complete FederatedSignOut method in FAM

   // When using native FederatedSignOut() no events for signout will be called, if you need this use the FAM SignOut methods instead.
}

このコードは、ACS を使用した Web SSO 用に作成された標準 RP ライブラリで使用されます。

于 2013-09-25T10:22:27.983 に答える
2

ACS の 2012 年 12 月の更新には、フェデレーション シングル サインアウトのサポートが含まれています。

WS-Federation プロトコルの使用。ACS を使用して、WS-Federation プロトコルを使用する ID プロバイダーでシングル サインオン (SSO) を有効にする Web アプリケーションは、シングル サインアウト機能を利用できるようになりました。ユーザが Web アプリケーションからサインアウトすると、ACS は自動的に ID プロバイダーからサインアウトし、同じ ID プロバイダーを使用する他の証明書利用者アプリケーションからサインアウトできます。

この機能は、Active Directory フェデレーション サービス 2.0 や Windows Live ID (Microsoft アカウント) などの WS-Federation ID プロバイダーに対して有効です。シングル サインアウトを有効にするために、ACS は WS-Federation プロトコル エンドポイントに対して次のタスクを実行します。

  • ACS は ID プロバイダーからの wsignoutcleanup1.0 メッセージを認識し、証明書利用者アプリケーションに wsignoutcleanup1.0 メッセージを送信して応答します。

  • ACS は、証明書利用者アプリケーションからの wsignout1.0 および wreply メッセージを認識し、wsignout1.0 メッセージを ID プロバイダーに送信し、wsignoutcleanup1.0 メッセージを証明書利用者アプリケーションに送信して応答します。

コード サンプル: ASP.NET MVC 4 with Federated Sign-out から、次のようなアクションを実装して ACS からサインアウトします。

(Windows Identity Foundation は現在 .NET 4.5 Framework に組み込まれていることに注意してください。そのため、以下の新しい名前空間が使用されています)

using System.IdentityModel.Services;
using System.IdentityModel.Services.Configuration;

public ActionResult Logout()
{
    // Load Identity Configuration
    FederationConfiguration config = FederatedAuthentication.FederationConfiguration;

    // Get wtrealm from WsFederationConfiguation Section
    string wtrealm = config.WsFederationConfiguration.Realm;
    string wreply;

    // Construct wreply value from wtrealm (This will be the return URL to your app)
    if (wtrealm.Last().Equals('/'))
    {
        wreply = wtrealm + "Logout";
    }
    else
    {
        wreply = wtrealm + "/Logout";
    }

    // Read the ACS Ws-Federation endpoint from web.Config
    // something like "https://<your-namespace>.accesscontrol.windows.net/v2/wsfederation"
    string wsFederationEndpoint = ConfigurationManager.AppSettings["ida:Issuer"];

    SignOutRequestMessage signoutRequestMessage = new SignOutRequestMessage(new Uri(wsFederationEndpoint));

    signoutRequestMessage.Parameters.Add("wreply", wreply);
    signoutRequestMessage.Parameters.Add("wtrealm", wtrealm);

    FederatedAuthentication.SessionAuthenticationModule.SignOut();

    string signoutUrl = signoutRequestMessage.WriteQueryString();

    return this.Redirect(signoutUrl);
}
于 2013-03-15T17:26:20.887 に答える