以编程方式从 Azure ACS 获取用户标识



这个问题有点菜鸟,但我无法通过互联网找到信息(也许我搜索错误?

我们配置了一个 Azure ACS,并将其用作我们网站的身份验证服务。但是现在我们需要构建一个应用程序,通过已知的用户名和密码,该应用程序将接收来自 ACS 的用户声明。这可能吗?

是的,这是可能的。

需要注意的一件事 - 使用 ACS,您可以选择各种不同的令牌提供程序来允许(也称为 STS-es)。 其中每个都默认提供一组不同的声明,因此可能需要扩充这些声明。

下面是一段代码,你可以尝试在代码中查看 ACS 已返回哪些声明:

// NOTE: This code makes the assumption that you have .NET 4.5 on the machine.  It relies on 
// the new System.Security.Claims.ClaimsPrincipal and System.Security.Claims.ClaimsIdentity
// classes.
// Cast the Thread.CurrentPrincipal and Identity
System.Security.Claims.ClaimsPrincipal icp = Thread.CurrentPrincipal as System.Security.Claims.ClaimsPrincipal;
System.Security.Claims.ClaimsIdentity claimsIdentity = icp.Identity as System.Security.Claims.ClaimsIdentity;
// Access claims
foreach (System.Security.Claims.Claim claim in claimsIdentity.Claims)
{
    Response.Write("Type : " + claim.Type + "- Value: " + claim.Value + "<br/>");
}

亚当·霍夫曼Windows Azure 博客 - http://stratospher.es推特 - http://twitter.com/stratospher_es

最新更新