ローカル ボックスで適切に機能するアクティブなフェデレーション エンドポイントを持つカスタム STS があります。ローカル URL は「https://localhost/CustomIDP/Service.svc」です。
SAML トークンを取得する最終ステップで Azure でホストした後、STS からトークンを取得中に次のエラーが発生します。
[System.ServiceModel.CommunicationException] {""https:// mysts .cloudapp.net/Service.svc" への HTTP 応答を受信中にエラーが発生しました。これは、HTTP プロトコルを使用していないサービス エンドポイント バインディングが原因である可能性があります。 HTTP リクエスト コンテキストがサーバーによって中止されたことが原因である可能性もあります (サービスのシャットダウンが原因である可能性があります。詳細については、サーバー ログを参照してください。"}
InnerException: [System.Net.WebException]: {"基になる接続が閉じられました: 受信時に予期しないエラーが発生しました。"}
InnerException: [System.IO.IOException]:{"トランスポート接続からデータを読み取れません: 既存の接続がリモート ホストによって強制的に閉じられました。"}
InnerException: [System.Net.Sockets.SocketException]: {"既存の接続がリモート ホストによって強制的に閉じられました"}: System.Net.Sockets.Socket.Receive(Byte[] バッファー、Int32 オフセット、Int32 サイズ、SocketFlags でsocketFlags) で System.Net.Sockets.NetworkStream.Read(Byte[] バッファー、Int32 オフセット、Int32 サイズ)
入力に感謝します。SAML トークンを取得するために STS を呼び出すために使用されるコード スニペットを以下に示します。エラーは channel.Issue ステートメントで発生します。
using (var factory = new WSTrustChannelFactory(
new UserNameWSTrustBinding(SecurityMode.TransportWithMessageCredential),
new EndpointAddress(new Uri(stsEndpoint))))
{
factory.Credentials.UserName.UserName = username;
factory.Credentials.UserName.Password = password;
factory.TrustVersion = TrustVersion.WSTrust13;
WSTrustChannel channel = null;
try
{
var rst = new RequestSecurityToken
{
RequestType = WSTrust13Constants.RequestTypes.Issue,
AppliesTo = new EndpointAddress(realm),
KeyType = KeyTypes.Bearer,
};
channel = (WSTrustChannel)factory.CreateChannel();
return channel.Issue(rst);
}
finally
{
if (channel != null)
{
channel.Abort();
}
factory.Abort();
}
}
Azure でホストされる STS サービスのサービス構成:
<system.serviceModel>
<services>
<service name="Microsoft.IdentityModel.Protocols.WSTrust.WSTrustServiceContract" behaviorConfiguration="ServiceBehavior">
<endpoint address="" binding="ws2007HttpBinding" contract="Microsoft.IdentityModel.Protocols.WSTrust.IWSTrust13SyncContract" bindingConfiguration="ws2007HttpBindingConfiguration"/>
<endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" />
</service>
</services>
<bindings>
<ws2007HttpBinding>
<binding name="ws2007HttpBindingConfiguration">
<security mode="TransportWithMessageCredential">
<message clientCredentialType="UserName" establishSecurityContext="false" />
</security>
</binding>
</ws2007HttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehavior">
<serviceMetadata httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
<serviceCredentials>
<serviceCertificate x509FindType="FindByThumbprint" findValue="[thumbprint]" storeLocation="LocalMachine" storeName="My" />
</serviceCredentials>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
<microsoft.identityModel>
<service>
<!-- User name and password are not authenticated by windows authentication but a custom verification is done -->
<securityTokenHandlers>
<remove type="Microsoft.IdentityModel.Tokens.WindowsUserNameSecurityTokenHandler, Microsoft.IdentityModel, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add type="ActiveIdPSite.CustomUserNameSecurityTokenHandler, ActiveIdPSite" />
</securityTokenHandlers>
<serviceCertificate>
<certificateReference x509FindType="FindByThumbprint" findValue="[thumbprint]" storeLocation="LocalMachine" storeName="My" />
</serviceCertificate>
<certificateValidation certificateValidationMode="None" />
</service>
</microsoft.identityModel>