WCF/WIF - 我应该在后端找到索赔吗?

Mih*_*riu 5 wcf claims-based-identity wif

我有一个ASP.NET应用程序调用WCF服务.在ASP.NET应用程序中,我调用ADFS来执行身份验证,我可以在CurrentPrincipal中看到用户的所有声明.然后我执行WCF服务的调用(wsHttpBinding),但声明列表为空.

可能是什么原因?

jta*_*loc 3

如果我没记错的话,有不同的方法可以在 WCF 中获得索赔。

Thread.CurrentPrincipal - 简单且易于使用,但需要在配置中进行一些设置,这是最容易被忽视的。

<behaviors>
  <serviceBehaviors>
    <behavior name="Test.Services.WifBehavior">
      <serviceCredentials useIdentityConfiguration="true" />
        <!---Set principalPermissionMode to always to pass the ClaimsIdentity info to the Thread.CurrentPrincipal-->
      <serviceAuthorization principalPermissionMode="Always"/>
    </behavior>
  <serviceBehaviors>
</behaviors>
Run Code Online (Sandbox Code Playgroud)

OperationContext.Current.ClaimsPrincipal - 我不记得这是否需要一些配置,但我想您可以直接从调用的方法中获取它。

OperationContext.ServiceSecurityContext.AuthorizationContext.ClaimSets -为服务创建自定义授权管理器,需要添加到配置中。

请注意,我使用了 Windows Identity Foundation (WIF)。