如何:配置本地颁发者

本主题说明如何配置客户端以便为已颁发令牌使用本地颁发者。

当客户端与联合服务通信时,服务端通常指定安全令牌服务的地址,客户端需要该安全令牌服务来颁发客户端用于向联合服务对自己进行身份验证的令牌。在某些情况下,可以将客户端配置成使用本地颁发者**。

当联合绑定的颁发者地址为 https://schemas.microsoft.com/2005/12/ServiceModel/Addressing/Anonymousnull 时,Windows Communication Foundation (WCF) 使用本地颁发者。在这样的情况下,必须使用本地颁发者的地址和要使用的绑定来配置 ClientCredentials,这样才能与该颁发者通信。

Aa347715.note(zh-cn,VS.100).gif注意:
如果 ClientCredentials 类的 SupportInteractive 属性设置为 true、未指定本地颁发者的地址以及由 wsFederationHttpBinding element 或其他联合绑定指定的颁发者地址为 https://schemas.xmlsoap.org/ws/2005/05/identity/issuer/self、https://schemas.microsoft.com/2005/12/ServiceModel/Addressing/Anonymous 或 null,则会使用 Windows CardSpace 颁发者。

在代码中配置本地颁发者

  1. 创建一个类型为 IssuedTokenClientCredential 的变量

  2. 将该变量设置为从 ClientCredentials 类的 IssuedToken 属性返回的实例。该实例由客户端的 ClientCredentials 属性(继承自 ClientBase)或 ChannelFactoryCredentials 属性返回:

    Dim itcc As IssuedTokenClientCredential = client.ClientCredentials.IssuedToken
    
    IssuedTokenClientCredential itcc = client.ClientCredentials.IssuedToken;
    
  3. LocalIssuerAddress 属性设置为 EndpointAddress 的一个新实例,将本地颁发者的地址作为传递给构造函数的参数。

    itcc.LocalIssuerAddress = New EndpointAddress("https://fabrikam.com/sts")
    
    itcc.LocalIssuerAddress = new EndpointAddress("https://fabrikam.com/sts");
    

    或者,创建一个新的 Uri 实例作为传递给构造函数的参数。

    itcc.LocalIssuerAddress = New EndpointAddress( _
    New Uri("https://fabrikam.com/sts"), addressHeaders)
    
    itcc.LocalIssuerAddress = new EndpointAddress(new Uri("https://fabrikam.com/sts"),
        addressHeaders);
    

    addressHeaders 参数是 AddressHeader 实例的数组,如下所示。

    itcc.LocalIssuerAddress = New EndpointAddress(New Uri("https://fabrikam.com/sts"), _
    EndpointIdentity.CreateDnsIdentity("fabrikam.com"), addressHeaders)
    
    itcc.LocalIssuerAddress = new EndpointAddress(
        new Uri("https://fabrikam.com/sts"),
        EndpointIdentity.CreateDnsIdentity("fabrikam.com"),
        addressHeaders);
    
  4. 使用 LocalIssuerBinding 属性设置本地颁发者的绑定。

    itcc.LocalIssuerBinding = New WSHttpBinding("LocalIssuerBinding")
    
    itcc.LocalIssuerBinding = new WSHttpBinding("LocalIssuerBinding");
    
  5. 可选。为本地颁发者添加已配置的终结点行为,方法是将这些行为添加到由 LocalIssuerChannelBehaviors 属性返回的集合中。

    itcc.LocalIssuerChannelBehaviors.Add(myEndpointBehavior)
    
    itcc.LocalIssuerChannelBehaviors.Add(myEndpointBehavior);
    

在配置中配置本地颁发者

  1. 创建一个 <localIssuer> 元素作为 <issuedToken> 元素的子级,而后者本身是终结点行为中 <clientCredentials> 元素的子级。

  2. address 属性设置为将要接收令牌请求的本地颁发者的地址。

  3. bindingbindingConfiguration 属性设置为这样的值,即在与本地颁发者终结点通信时,这些值可引用要使用的适当绑定。

  4. 可选。将 <identity> 元素设置为 <localIssuer> 元素的子项,并为本地颁发者指定标识信息。

  5. 可选。将 <headers> 元素设置为 <localIssuer> 元素的子项,并指定正确寻址本地颁发者所需的其他标头。

安全性

请注意,如果颁发者地址和绑定是为给定的绑定而指定的,则不对使用该绑定的终结点使用本地颁发者。希望始终使用本地颁发者的客户端应该确保不使用这样的绑定,或修改该绑定,使颁发者地址为 null

另请参见

任务

如何:在联合身份验证服务上配置凭据
如何:创建联合客户端
如何:创建 WSFederationHttpBinding