web-dev-qa-db-ja.com

エラー-SignInResponseメッセージは、現在のWebアプリケーション内でのみリダイレクトされる可能性があります-MVC 2.0アプリケーション

MVC 2アプリケーションがあり(私は基本的なMVC 2アプリでこれを試しましたが、余分なものはありませんが、同じ問題があります)、ユーザーの認証にadfs 2を使用しています。

つまり、アプリケーションにアクセスすると、以下が表示されます。ID3206:SignInResponseメッセージは、現在のWebアプリケーション内でのみリダイレクトされる場合があります: '/ [app]'は許可されていません。説明:現在のWeb要求の実行中に未処理の例外が発生しました。エラーの詳細とコードのどこで発生したかについては、スタックトレースを確認してください。例外の詳細:Microsoft.IdentityModel.Protocols.FederationException:ID3206: SignInResponseメッセージは、現在のWebアプリケーション内でのみリダイレクトできます: '/ [app]'は許可されません。

私はこれに関するほとんどのブログを読み、1つに投稿しました。

    <federatedAuthentication>
            <wsFederation passiveRedirectEnabled="true" issuer="https://auth.[domain]/adfs/ls/" realm="https://[development domain]/[app]/" requireHttps="true" />
            <cookieHandler requireSsl="true" />
          </federatedAuthentication>
<audienceUris>
    <add value="https://[development domain]/[app]/" />
  </audienceUris>
  1. レルムとaudienceUrisの末尾にスラッシュがあります。
  2. 彼が提案したことをApplication_BeginRequestに追加しました。次に、証明書が存在する場所としてコードを[開発ドメイン]にコピーしました。そのとき、無限ループに陥ります。
  3. Genevaサーバーで証明書利用者も確認しました。識別子とエンドポイント(POST)はどちらもhttps:// [開発ドメイン]/[アプリ] /です-末尾にスラッシュを付けます

それはMVCアプリケーションであるという事実に問題があると思います。多数のClaims Aware Webサイトを作成し、default.aspxページでクレームなどを取得しました。私の考えは、MVCアプリに関連するルーティングがどういうわけかそれを間違ってポストバックしているということですか?

しばらくの間静かにこれを探しているイムが役に立たないので、本当に助けられた助けは..

J

36
John

私はこれで髪をちぎりました。私も私の設定で末尾のスラッシュを指定しています。私の場合、ブラウザで末尾にスラッシュを付けてアプリに移動すると、次のようになります。

http:// localhost/myapp /

動作しますが、

http:// localhost/myapp

しない。

これが事実である理由をさらに掘り下げることができる場合は、これがなぜ起こっているのかについていくつかの背景を追加します。

35
Dave Markle

RedirectToIdentityProviderのサブクラスのWSFederationAuthenticationModuleをオーバーライドします。これは、STSにリダイレクトする前に1回だけ発生します。構成ファイルに、デフォルトのFixedWSFederationAuthenticationModuleの代わりにこのクラスWSFederationAuthenticationModuleを使用するように指示する必要があります

public class FixedWSFederationAuthenticationModule : WSFederationAuthenticationModule
{
    public override void RedirectToIdentityProvider(string uniqueId, string returnUrl, bool persist)
    {
        //This corrects WIF error ID3206 "A SignInResponse message may only redirect within the current web application:"
        //First Check if the request url doesn't end with a "/"
        if (!returnUrl.EndsWith("/"))
        {
            //Compare if Request Url +"/" is equal to the Realm, so only root access is corrected
            //https://localhost/AppName plus "/" is equal to https://localhost/AppName/
            //This is to avoid MVC urls
            if (String.Compare(System.Web.HttpContext.Current.Request.Url.AbsoluteUri + "/", base.Realm, StringComparison.InvariantCultureIgnoreCase) == 0)
            {
                //Add the trailing slash
                returnUrl += "/";
            }
        }
        base.RedirectToIdentityProvider(uniqueId, returnUrl, persist);
    }
}
18
user1496129

このコードはそれを処理します(global.asaxに入れます):

private void Application_BeginRequest(object sender, EventArgs e)
{
//  This corrects WIF error ID3206 "A SignInResponse message may only redirect within the current web application: '/NHP' is not allowed."
//  For whatever reason, accessing the site without a trailing slash causes this error.
if (String.Compare(Request.Path, Request.ApplicationPath, StringComparison.InvariantCultureIgnoreCase) == 0 && !(Request.Path.EndsWith("/")))
Response.Redirect(Request.Path + "/");
}

編集:

チェックするもう1つのことは、Web.configのMicrosoft.identityModelのfederationAuthentication/wsFederation要素です。発行者とレルムが正しいことを確認してください。

10
Mike Cheel

WIFでフォーム認証を使用しています。フォーム認証モジュールは不正なリクエストを正しいコントローラにリダイレクトし、最初にリクエストされたURLをReturnUrlパラメータに格納するため、GetReturnUrlFromResponseメソッドをオーバーライドしてこのバグを回避しました。

/// <summary>
/// Provides a workaround for a bug in the standard authentication module.
/// </summary>
/// <remarks>
/// This class corrects WIF error ID3206 "A SignInResponse message may only
/// redirect within the current web application..."
/// WSFAM produces the error when the ReturnUrl is the root of the web application,
/// but doesn't have a trailing slash. For instance, "/app" is considered incorrect
/// by WSFAM whereas "/app/" is correct.
/// </remarks>
public class FixedWsFederationAuthenticationModule : System.IdentityModel.Services.WSFederationAuthenticationModule
{
    /// <summary>
    /// Extracts the URL of the page that was originally requested from
    /// the sign-in response.
    /// </summary>
    /// <returns>
    /// The URL of the page that was originally requested by the client.
    /// This is the URL (at the relying party) to which the client should
    /// be redirected following successful sign-in.
    /// </returns>
    /// <param name="request">
    /// The HTTP request that contains a form POST, which contains the
    /// WS-Federation sign-in response message.
    /// </param>
    protected override string GetReturnUrlFromResponse(HttpRequestBase request)
    {
        string returnUrl = base.GetReturnUrlFromResponse(request);

        // First Check if the request url doesn't end with a "/"
        if (!string.IsNullOrEmpty(returnUrl) && !returnUrl.EndsWith("/"))
        {
            // Compare if (return Url +"/") is equal to the Realm path,
            // so only root access is corrected.
            // /AppName plus "/" is equal to /AppName/
            // This is to avoid MVC urls.
            if (string.Compare(
                returnUrl + "/",
                new Uri(Realm).LocalPath,
                StringComparison.InvariantCultureIgnoreCase) == 0)
            {
                // Add the trailing slash.
                returnUrl += "/";
            }
        }

        return returnUrl;
    }
}

このクラスを使用するには、web.configに登録する必要があります。この要素をsystem.webServer/modulesセクションに追加し、適切な部分を変更します。

<add name="WSFederationAuthenticationModule" type="YOUR_NAMESPACE.FixedWsFederationAuthenticationModule, YOUR_Assembly" preCondition="managedHandler" />
5
Gebb

デフォルトで動的ポートの仮想サーバーの下で実行されるWebアプリケーションにSTS参照を追加すると、この問題が発生しました。 IISから実行するように変更しました(仮想Webサーバーと同様に、IIS/IIS Expressから実行しない限り、STSへのリダイレクトは行われません。 )、web.configで手動で編集して、Microsoft.IdentityModel構成でオーディエンスURIを変更します。

FederationMetadata.xmlを確認したところ、古い場所(動的ポートを使用)がまだ参照されていました。 STSリファレンスを再度追加して更新しましたが、うまくいきました。

2
Badal