2013-03-11 60 views
0

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

有没有人有如何做到这一点的例子?

回答

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))); 
    } 
0

您将依赖方的token format配置为指定由ACS颁发令牌的格式。我建议您查看Protocols Supported in ACS,因为如果您计划将应用程序(依赖方)与ACS集成在一起,您将利用这些协议之一。 Token Formats Supported in ACS涵盖了令牌格式的差异,并帮助您决定哪个是您的依赖方的最佳选择。

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

相关问题