4

2 つの別々のドメインでサイトを実行しています。1 つは安全な API で、もう 1 つはフロントエンド Web サイトです。現在ログインしているユーザーの資格情報を使用して、ウェブサイトから API への ajax リクエストを実行できるようにしたいと考えています。

ここに画像の説明を入力

これを行うために、Cookie を API に渡すために必要なすべての CORS ビットを実行しましたが、API が Cookie を処理しようとすると、復号化できません。私の理解では、これはレルムが正しく一致していないためです。

これを実行しようとすると発生するエラーは次のとおりです。

InvalidOperationException: ID1073: ProtectedData API を使用して Cookie を復号化しようとしたときに、CryptographicException が発生しました (詳細については、内部例外を参照してください)。IIS 7.5 を使用している場合、これはアプリケーション プールの loadUserProfile 設定が false に設定されていることが原因である可能性があります。

:1444 レルムの Cookie を使用して手動で同じリクエストを行うと、すべてが正しく機能します (したがって、loadUserProfile の内容は問題だと思います)。

問題は、この Cookie を別の領域に再利用できないことだと思います。しかし、これが当てはまる場合、この委任をjavascriptで実行するにはどうすればよいですか? 実際にユーザーを STS にリダイレクトせずに、他のレルムの Cookie を取得することは実際に可能ですか? この JavaScript 委任にアプローチするより良い方法はありますか?

有用な補足データ:

API エンドの WIF の構成:

    <modules runAllManagedModulesForAllRequests="true">
        <add name="WSFederationAuthenticationModule" type="Microsoft.IdentityModel.Web.WSFederationAuthenticationModule, Microsoft.IdentityModel, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" preCondition="managedHandler" />
        <add name="SessionAuthenticationModule" type="Microsoft.IdentityModel.Web.SessionAuthenticationModule, Microsoft.IdentityModel, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" preCondition="managedHandler" />
    </modules>

...

<microsoft.identityModel>
    <service>
        <securityTokenHandlers>
            <add type="Microsoft.IdentityModel.Tokens.SessionSecurityTokenHandler, Microsoft.IdentityModel, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
                <sessionTokenRequirement lifetime="1:00" />
            </add>
        </securityTokenHandlers>
        <audienceUris>
            <add value="http://localhost:1444/" />
        </audienceUris>
        <federatedAuthentication>
            <wsFederation passiveRedirectEnabled="true" issuer="http://localhost:1339/account/sign-in" realm="http://localhost:1444/" requireHttps="false" persistentCookiesOnPassiveRedirects="false" />
            <cookieHandler requireSsl="false" path="/" name="TheCookieMonster" persistentSessionLifetime="60" />
        </federatedAuthentication>
        <applicationService>
            <claimTypeRequired>
                <!--This claim gets mapped to the User.Identity.Name-->
                <claimType type="http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name" optional="false" />
                <!--Some Other Custom claims-->
            </claimTypeRequired>
        </applicationService>
        <issuerNameRegistry type="Microsoft.IdentityModel.Tokens.ConfigurationBasedIssuerNameRegistry, Microsoft.IdentityModel, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
            <trustedIssuers>
                <add thumbprint="a_thumbprint_key_for_our_cert" name="http://localhost:1339/" />
            </trustedIssuers>
        </issuerNameRegistry>
    </service>
</microsoft.identityModel>

Web サイト側の WIF の構成:

(同じですが、:1337)

    <modules runAllManagedModulesForAllRequests="true">
        <add name="WSFederationAuthenticationModule" type="Microsoft.IdentityModel.Web.WSFederationAuthenticationModule, Microsoft.IdentityModel, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" preCondition="managedHandler" />
        <add name="SessionAuthenticationModule" type="Microsoft.IdentityModel.Web.SessionAuthenticationModule, Microsoft.IdentityModel, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" preCondition="managedHandler" />
    </modules>

...

<microsoft.identityModel>
    <service>
        <securityTokenHandlers>
            <add type="Microsoft.IdentityModel.Tokens.SessionSecurityTokenHandler, Microsoft.IdentityModel, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
                <sessionTokenRequirement lifetime="1:00" />
            </add>
        </securityTokenHandlers>
        <audienceUris>
            <add value="http://localhost:1337/" />
        </audienceUris>
        <federatedAuthentication>
            <wsFederation passiveRedirectEnabled="true" issuer="http://localhost:1339/account/sign-in" realm="http://localhost:1337/" requireHttps="false" persistentCookiesOnPassiveRedirects="false" />
            <cookieHandler requireSsl="false" path="/" name="TheCookieMonster" persistentSessionLifetime="60" />
        </federatedAuthentication>
        <applicationService>
            <claimTypeRequired>
                <!--This claim gets mapped to the User.Identity.Name-->
                <claimType type="http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name" optional="false" />
                <!--Some Custom claims-->
            </claimTypeRequired>
        </applicationService>
        <issuerNameRegistry type="Microsoft.IdentityModel.Tokens.ConfigurationBasedIssuerNameRegistry, Microsoft.IdentityModel, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
            <trustedIssuers>
                <add thumbprint="a_thumbprint_key_for_our_cert" name="http://localhost:1339/" />
            </trustedIssuers>
        </issuerNameRegistry>
    </service>
</microsoft.identityModel>

ネットタブは次のようになります。

ここに画像の説明を入力

JS がある種のセキュリティのナンセンスが起こっていることを検出したため、これはキャンセルされたと思います。

  • マシン キーは両方のサイトで共有されます
  • どちらもWIF 3.5を実行しています
4

1 に答える 1

1

特別な変更なしで完全に機能する WIF 4.5 にアップグレードすることで、これを解決することができました。3.5 の根本的な原因が何であるかはよくわかりませんが、これで問題は解決しました。誰かがそれを望んでいるなら、これが機能するサンプルを GitHub に投稿できます

于 2013-09-04T22:28:44.703 に答える