2013-03-11 61 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令牌並在作出授權決定時提取聲明的聲明。

相關問題