我可以从ACS获取JSON格式数据吗?

时间:2013-03-11 13:51:39

标签: azure acs

当我开始阅读ACS 2.0文档时,我意识到,ACS集成了基于声明的身份验证。 因此,如果我不想在我的应用程序中使用声明,我应该如何获取SWT或JSON格式的数据?

有没有人有如何实现这个目标的例子?

2 个答案:

答案 0 :(得分:0)

您配置信赖方的token format以指定ACS发出的令牌的格式。我建议您查看Protocols Supported in ACS,因为如果您计划将应用程序(依赖方)与ACS集成,您将利用其中一种协议。 Token Formats Supported in ACS涵盖令牌格式的差异,并帮助您确定哪个是您的信赖方的最佳选择。

无论您选择发布的令牌格式(SAML,JWT,SWT)如何,您的依赖方都将负责在做出授权决策时验证Web令牌并提取声明的声明。

答案 1 :(得分:0)

最简单的解决方案:切换ACS以使用SWT令牌,配置您的应用程序以保存引导令牌并以您的方式使用它们 web.config中:

<system.identityModel>
    <identityConfiguration saveBootstrapContext="true">

应用:

var claimIdentity = Thread.CurrentPrincipal.Identity as ClaimsIdentity;
if (claimIdentity == null)
{
    return;
}

BootstrapContext bootstrapContext = claimIdentity.BootstrapContext as BootstrapContext;
SecurityToken token = null;
//you must configure SWT token handler in web.config or set up 'em manually like
SecurityTokenHandlerCollection handlers = FederatedAuthentication.FederationConfiguration.IdentityConfiguration.SecurityTokenHandlers;
//here is a bug in 4.5 cause a bootstrapContext.SecurityToken disappear sometimes. 
//http://blogs.msdn.com/b/vbertocci/archive/2012/11/30/using-the-bootstrapcontext-property-in-net-4-5.aspx
if (bootstrapContext.SecurityToken != null)
    {
        token = bootstrapContext.SecurityToken;
    }
else if (!string.IsNullOrEmpty(bootstrapContext.Token))
    {
        token = handlers.ReadToken(new XmlTextReader(new StringReader(bootstrapContext.Token)));
    }