WCF、索赔、ADFS 3.0

Fab*_*Fab 5 .net c# wcf adfs claims

我试图了解使用 WCF、Claims 和 ADFS 3.0 开发框架需要什么。内部用户将根据 Active Directory 进行身份验证,外部用户将根据 SQL Server 表进行身份验证,并且授权存储在实现组和权限的数据库表中。我正在使用 WCF 而不是 Web Api 或 OWIN 创建 API。

我对使用 Identity Server 或 3rd 方产品不感兴趣,我只想知道如何创建自定义安全令牌服务以从我的成员资格表中读取并通过我的组和权限表设置声明。

我找不到任何有关此的信息。Visual Studio 2015 中没有身份和访问控制,似乎没有使用 WCF,只使用 Web Api、OWIN 和 MVC?

Jas*_*yne 1

这篇文章似乎对您来说有一个好的开始,http://southworks.com/blog/2007/03/11/the-holly-grail-of-enterprise-soa-security/

这是我在 MVC 应用程序中使用的代码(不是 WCF,但许多需要完成的事情是相同的)

var claims = new List<Claim>()
            {
                new Claim(ClaimTypes.Name, result.UserName),
                new Claim("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier", result.Email),
                new Claim("http://schemas.microsoft.com/accesscontrolservice/2010/07/claims/identityprovider",
                    result.Email),
                new Claim("UserId", result.Id.ToString(CultureInfo.InvariantCulture)),
                new Claim("UserName", result.UserName),
                new Claim("FirstName", result.FirstName)
            };

        //load claims from database here
        claims.AddRange(result.Roles.Select(role => new Claim(ClaimTypes.Role, role.Name)));

        var id = new ClaimsIdentity(claims, "Forms");
        var cp = new ClaimsPrincipal(id);
        var token = new SessionSecurityToken(cp)
        {
            IsPersistent = false

        };

        Session["authToken"] = token;

        var sam = FederatedAuthentication.SessionAuthenticationModule;
        sam.WriteSessionTokenToCookie(token);
Run Code Online (Sandbox Code Playgroud)