1

件名に記載されているセットアップに苦労しており、誰かが私を助けてくれるかどうか疑問に思っています。

基本的に、私が持っているのはWCFサービスであり、カスタムログインページを使用して(ACSからの必要な情報を含むjavascriptを使用して)ユーザーがACSに対して認証できるようにしたいと考えています。

それを行った後、ユーザーは提供された SWT トークンを使用して WCF サービスにリダイレクトされます。SWT トークン処理の基礎として SimpleWebTokenHandler を使用していますが、これが何らかの役割を果たしているかどうかはわかりません。

これが私が実行しているWeb.configです

<configuration>
    <configSections>
        <section name="system.identityModel" type="System.IdentityModel.Configuration.SystemIdentityModelSection, System.IdentityModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
        <section name="system.identityModel.services" type="System.IdentityModel.Services.Configuration.SystemIdentityModelServicesSection, System.IdentityModel, Version=4.0.0.0, Culture=neutral" />
    </configSections>
    ...
    <system.serviceModel>
        <diagnostics>
        </diagnostics>
        <services>
            <service name="WcfWifSwtAcs.Service1">
                <endpoint address="xmlService" binding="webHttpBinding" bindingConfiguration="" behaviorConfiguration="restPoxBehaviour" name="xmlServiceEndpoint" contract="WcfWifSwtAcs.IService1" />
            </service>
        </services>
        <behaviors>
            <endpointBehaviors>
                <behavior name="restPoxBehaviour">
                    <webHttp helpEnabled="true" />
                </behavior>
            </endpointBehaviors>
            <serviceBehaviors>
                <behavior>
                    <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
                    <serviceDebug includeExceptionDetailInFaults="true" />
                    <serviceCredentials useIdentityConfiguration="true">
                        ...
                    </serviceCredentials>
                </behavior>
            </serviceBehaviors>
        </behaviors>
        <protocolMapping>
            <add scheme="http" binding="ws2007FederationHttpBinding" />
        </protocolMapping>
        <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
        <bindings>
            <ws2007FederationHttpBinding>
                <binding name="">
                    <security mode="Message">
                        <message 
                            issuedTokenType="http://schemas.xmlsoap.org/ws/2009/11/swt-token-profile-1.0">
                            <issuerMetadata address="https://xxxx.accesscontrol.windows.net/v2/wstrust/13/certificate/mex" />
                        </message>
                    </security>
                </binding>
            </ws2007FederationHttpBinding>
        </bindings>
    </system.serviceModel>
    <system.webServer>
    ...
    </system.webServer>
    <system.identityModel>
        <identityConfiguration>
            <audienceUris>
                <add value="http://localhost:56782/Service1.svc" />
            </audienceUris>
            <issuerNameRegistry type="System.IdentityModel.Tokens.ConfigurationBasedIssuerNameRegistry, System.IdentityModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
                <trustedIssuers>
                    <add thumbprint="XXX" name="xxx.accesscontrol.windows.net" />
                </trustedIssuers>
            </issuerNameRegistry>
        <issuerTokenResolver type="SimpleWebToken.CustomIssuerTokenResolver, WcfWifSwtAcs" />
            <securityTokenHandlers>
                <clear/>
                <add type="SimpleWebToken.SimpleWebTokenHandler, WcfWifSwtAcs"/>
            </securityTokenHandlers>
        </identityConfiguration>
    </system.identityModel>
</configuration>

これで、認証が行われ、ブラウザが本文とともにサービスにリダイレクトされることがわかります。また、SimpleWebToken ハンドラーがインスタンス化され、トークン タイプの URI が要求されていることもわかります。しかし、それがほとんどすべてです。実際のトークン処理の検証はなく、何も起こっていません。

これは、(解析後に) サービスに送信されるトークンです。

wa=wsignin1.0&
wresult=
<t:RequestSecurityTokenResponse 
xmlns:t="http://schemas.xmlsoap.org/ws/2005/02/trust">
<t:Lifetime>
    <wsu:Created 
        xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">2013-02-13T23:14:30.159Z</wsu:Created>
    <wsu:Expires
        xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">2013-02-13T23:24:30.159Z</wsu:Expires>
</t:Lifetime>
<wsp:AppliesTo 
    xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy">
    <EndpointReference
        xmlns="http://www.w3.org/2005/08/addressing">
        <Address>http://localhost:56782/Service1.svc</Address>
    </EndpointReference>
</wsp:AppliesTo>
<t:RequestedSecurityToken>
    <wsse:BinarySecurityToken 
        wsu:Id="uuid:58e2fb15-dd1a-40bd-8ff0-ae24e22e6efe" 
        ValueType="http://schemas.xmlsoap.org/ws/2009/11/swt-token-profile-1.0"
        EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary"
        xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"          xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
        BASE64 DATA==
    </wsse:BinarySecurityToken>
</t:RequestedSecurityToken>
<t:TokenType>http://schemas.xmlsoap.org/ws/2009/11/swt-token-profile-1.0</t:TokenType>
<t:RequestType>http://schemas.xmlsoap.org/ws/2005/02/trust/Issue</t:RequestType>
<t:KeyType>http://schemas.xmlsoap.org/ws/2005/05/identity/NoProofKey</t:KeyType>
</t:RequestSecurityTokenResponse>

サービス自体は非常に単純で、次の署名があります。

[OperationContract]
[WebInvoke(UriTemplate = "/GetData/{id}", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
string GetData(string id);

何か案は?URI、ホスト名、拇印などがすべて有効であることを確認しています。また、サービス トレースでは、トークン処理またはトークン検証の例外に関連するものは実際には何も表示されません。

どういうわけか、トークンがハンドラーに渡されていないように見えます。少なくともすべてのクレームとその他の認証情報が欠落しています (null)。

誰かがどこでデバッグできるか、または本当に明白な何かが欠けているかの方向を教えてくれれば幸いです(これは常にそうである可能性があります)。

PSカスタム認証モジュールでそれを達成できることは知っていますが、WIFで実行したいのですが(私が本当に望んでいたようにこれにより多くの時間を費やしており、非常に頑固です:p)。

4

2 に答える 2

1

スー、献身は人を解決に導きます。これは最初はできないと思っていましたが、実際にはできるようです。他の人が役に立つと思うかもしれないので、ここに解決策を載せます。

まず第一に、WCF REST サービスは を使用していますwebHttpBinding。これは、MS のドキュメントによると、Windows Identity Foundation とパイプラインでのクレーム処理をサポートしていません。実際そうです。WCF パイプラインではなく、Web 認証フローの IIS モジュールとして。

まず、次のモジュールを Web.config ファイルに追加する必要があります。

<system.webServer>
    <modules runManagedModulesForAllRequests="true">
        <add name="WSFederationAuthenticationModule" type="System.IdentityModel.Services.WSFederationAuthenticationModule, System.IdentityModel.Services, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" preCondition="managedHandler" />
        <add name="SessionAuthenticationModule" type="System.IdentityModel.Services.SessionAuthenticationModule, System.IdentityModel.Services, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" preCondition="managedHandler" />
    </modules>
 </system.webServer>

と、注意点があります。<configSections>私の元の投稿からまだ必要です。System.IdentyModel*問題は、VisualStudio でアセンブリをCopyLocalアイテムとしてマークする必要があることです(プロパティ ウィンドウで)。そうしないと、構成セクションのアセンブリを読み込めないという不可解な例外が発生します。注意!これら 2 つのモジュールをロードしている場合にのみ発生し、それらのモジュールがロードされていない場合は発生しません。そのことをさらに調査するつもりはありませんでした。おそらく、誰かがそこにある原因をよりよく知っています.

次に、何らかの理由で MS WIF コードの SWT トークン処理サンプルを使用する予定がある場合、修正が必要なバグがいくつかあります。修正しないと、トークンの解析が行われないか、トークンから無効な署名が取得されます。検証。

SimpleWebToken.cs SwtBaseTimeが正しく初期化されておらず、その後セキュリティ トークンの作成が失敗するため、SwtBaseTime を修正する必要があります。

public static DateTime から SwtBaseTime = new DateTime( 1970, 1, 1, 0, 0, 0, 0 ); // SWT psec あたり

public static DateTime SwtBaseTime = new DateTime( 1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc ); // per SWT psec

SimpleWebTokenHandler.cs では、次の値の大文字と小文字を修正する必要があります。

から

const string BinarySecurityToken = "binarySecurityToken";
const string ValueType = "valueType";

const string BinarySecurityToken = "BinarySecurityToken";
const string ValueType = "ValueType";

CustomIssuerTokenResolver.cs UTF8 バイトで初期化されたときに作成されたキーを修正する必要がありますが、実際にはデコードされた Base64 バイトで初期化する必要があります。

から

key = new InMemorySymmetricSecurityKey(UTF8Encoding.UTF8.FromBase64String(base64Key));

key = new InMemorySymmetricSecurityKey(System.Convert.FromBase64String(base64Key));

これをすべて修正したら、すべてが所定の位置に収まります。オーセンティケーターとオーソリゼーターが呼び出されて、突然、WCF サービスが REST エンドポイントとして公開され、すべてのクレームなども機能しています。

于 2013-02-19T21:54:41.987 に答える
0

このサンプルの SWTTokenHandler に問題がある可能性があると思います: http://code.msdn.microsoft.com/vstudio/Custom-Token-ddce2f55

CanReadToken() では、トークンが SWT タイプの BinarySecurityToken であるかどうかを確認します。

if ( reader.IsStartElement( BinarySecurityToken )
&& ( reader.GetAttribute( ValueType ) == SimpleWebTokenConstants.ValueTypeUri ) )

ただし、定数 BinarySecurityToken は次のように定義されています。

const string BinarySecurityToken = "binarySecurityToken";

小文字の「b」に注意してください。XML 要素は大文字と小文字が区別され、実際の要素は大文字の B を持つ "BinarySecurityToken" です。これにより、ハンドラーは CanReadToken() で false を返し、WIF はこのトークンの種類に登録されたハンドラーを持っていないと認識します。

于 2013-02-14T20:17:38.503 に答える