使用微软.SSIS包中的IdentityModel
本文关键字:IdentityModel 包中 SSIS 微软 | 更新日期: 2023-09-27 18:05:29
我需要在SSIS包中使用Microsoft.IdentityModel
dll。
在常规的c#应用程序中,我会将程序集添加到app.config文件中,如本网站添加Microsoft所示。IdentityModel
但是我不能在SSIS中使用这个,因为它们在脚本组件中没有app.config。
我试过添加一个app.config并将部分添加到app.config,但这不起作用。
我还尝试导入一个.xml文件用于包配置。
当我调试脚本时,我得到的确切错误是:
"ID7027: Could not load the identity configuration
because no <system.identityModel> configuration section was found."
我们使用SecurityTokenHandlerCollection handlers = FederatedAuthentication.FederationConfiguration.IdentityConfiguration.SecurityTokenHandlers;
来获取处理程序。
我们改成了
SecurityTokenHandlerCollection collection = SecurityTokenHandlerCollection.CreateDefaultSecurityTokenHandlerCollection();
token = collection.ReadToken(xmlReader.ReadSubtree());
下面是代码的用法
private static SecurityToken ConvertBearerTokenTextToSecurityToken(string tokenText)
{
SecurityToken token = null;
// ConfigSections must be added to App.Config in order for this line to work - this section must be right after the <configuration> node
//<configSections>
// <!--WIF 4.5 sections -->
// <section name="system.identityModel" type="System.IdentityModel.Configuration.SystemIdentityModelSection, System.IdentityModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
// <section name="system.identityModel.services" type="System.IdentityModel.Services.Configuration.SystemIdentityModelServicesSection, System.IdentityModel.Services, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
//</configSections>
//SecurityTokenHandlerCollection handlers = FederatedAuthentication.FederationConfiguration.IdentityConfiguration.SecurityTokenHandlers;
using (StringReader stringReader = new StringReader(tokenText))
{
using (XmlTextReader xmlReader = new XmlTextReader(stringReader))
{
if (!xmlReader.ReadToFollowing("Assertion"))
{
throw new Exception("Assertion not found!");
}
SecurityTokenHandlerCollection collection = SecurityTokenHandlerCollection.CreateDefaultSecurityTokenHandlerCollection();
token = collection.ReadToken(xmlReader.ReadSubtree());
}
}
return token;
}