Tag: wif

.NET Framework中的复杂声明值与System.Security.Claims

我正在使用Asp.Net 5 MVC,Owin和Oauth2 bearer token作为auth类型开发一个Web应用程序。 按照本指南将Json序列化的自定义复杂声明成功添加到Microsoft.IdentityModel.Claims.ClaimsIdentity实例,我尝试使用System.Security.Claims命名空间上的ClaimsIdentity复制相同的示例。 不幸的是,似乎将一个complexClaim添加到ClaimsIdentity实例,派生的类类型信息将丢失,并且声明将存储为System.Security.Claims.Claim 。 var complexClaim = new ComplexClaim(@”http://it.test/currentpassport”, passport); var claims = new List() { complexClaim }; identity.AddClaims(claims); 当我尝试从身份中取回声明时,将其转换为ComplexClaim Type会产生空值。 var passportClaim = identity.Claims.FirstOrDefault(c=>c.Type == @”http://it.test/currentpassport”) as ComplexClaim; 相同的示例使用Microsoft.IdentityModel.Claims完美运行。 任何提示? 这是完整的移植代码: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Newtonsoft.Json; using System.Security.Claims; namespace ConsoleApplication1 { class Program […]

是否可以在不编辑web.config的情况下获得ACS声明?

是否可以在不编辑web.config的情况下为azure ACS设置领域URL,声明类型等? 你能以某种方式以编程方式设置这些必需的元素吗? 编辑:具体我想摆脱这个: 基本上,我不希望在Web配置中指定域,而是在代码中指定。 我已经尝试重写ClaimsAuthenticationManager并将部分注释到与FederatedAuthentication相关的代码中。 我的被​​覆盖的身份validation代码被命中,但它不包含任何声明。 我假设这是因为FederatedAuthentication是一个中介,它在正常访问被覆盖的ClaimsAuthenticationManager之前执行自己的身份validation。 有没有办法以类似的方式覆盖FederatedAuthentication部分? 或者是否有信息传递到重写的身份validation方法,我可以用它来执行我自己的身份validation?

如何将SAML XML标记字符串转换为SecurityToken或ClaimsPrincipal实例?

我的背景: .Net RESTful Web服务 客户端(混合平台,技术,libfunction)已获得SAML令牌 尝试在REST服务中接受用于身份validation/授权的令牌 在HTTP授权/ X-Authorization标头中 作为查询参数 稍后还会支持SWT,但需要获得SAML令牌 细节: 我在字符串中有一个SAML令牌: ..etc… 在HttpModule中,我想将其转换为ClaimsPrincipal,以便我的服务可以将通常的Thread.CurrentPrincipal作为IClaimsPrincipal。 我找到了一些诱人的网页/博客/等……看起来很有帮助: Cibrax的想法是在HTTP Authorization标头中传递令牌 Dominick Baier在SWT上有类似的东西,提到SAML很容易做同样的事情 我实际上试图将SAML令牌转换为ClaimsPrincipal(通过SecurityToken中间步骤或直接……快乐)。 来自Cibrax的想法的示例代码使用以下内容进行关键validation和反序列化步骤: SecurityTokenSerializer securityTokenSerializer = new SecurityTokenSerializerAdapter( FederatedAuthentication.SecurityTokenHandlers, MessageSecurityVersion.Default.SecurityVersion, false, new SamlSerializer(), null, null); SecurityToken theToken = WSFederationAuthenticationModule.GetSecurityToken( theSamlTokenInStringForm, securityTokenSerializer); 我遇到的问题是,WIF的RTM版本没有公开GetSecurityToken的这个重载…它只暴露: WSFederationAuthenticationModule fam = new WSFederationAuthenticationModule(); SecurityToken theToken = fam.GetSecurityToken(HttpRequest theRequest); SecurityToken theToken = fam.GetSecurityToken(SignInResponseMessage message); […]

参考摘要validation失败

我实现了自定义STS。 经过身份validation和重定向但在页面加载之前,我会收到此错误: [CryptographicException: Digest verification failed for Reference ‘#_8e0aea1a-713d-4536-8fac-a768073395e9’.] 每次尝试时参考编号都会改变。

使用.NET 4.5(System.IdentityModel)/ WIF解密SAML 2断言

我正在尝试解密从基于Java的身份提供程序发出的加密SAML 2.0断言。 鉴于以下安全令牌处理程序的设置: X509Certificate2 cert = … // Contains private key var serviceTokens = new List(); serviceTokens.Add(new X509SecurityToken(cert)); var issuers = new ConfigurationBasedIssuerNameRegistry(); issuers.AddTrustedIssuer(“…thumbprint…”, “nottherealname”); var configuration = new SecurityTokenHandlerConfiguration { AudienceRestriction = { AudienceMode = AudienceUriMode.Never }, CertificateValidationMode = X509CertificateValidationMode.None, RevocationMode = X509RevocationMode.NoCheck, IssuerNameRegistry = issuers, MaxClockSkew = TimeSpan.FromMinutes(5), ServiceTokenResolver = SecurityTokenResolver.CreateDefaultSecurityTokenResolver(serviceTokens.AsReadOnly(), false) }; […]

如何加密JWT安全令牌?

我需要通过签名和加密来保护我的网络令牌。 我编写了下一行代码: var tokenHandler = new JwtSecurityTokenHandler(); var tokenDescriptor = new SecurityTokenDescriptor { Subject = new ClaimsIdentity(new[] { new Claim(ClaimTypes.Name, owner.Name), new Claim(ClaimTypes.Role, owner.RoleClaimType), new Claim(“custom claim type”, “custom content”) }), TokenIssuerName = “self”, AppliesToAddress = “http://www.example.com”, Lifetime = new Lifetime(now, now.AddSeconds(60 * 3)), EncryptingCredentials = new X509EncryptingCredentials(new X509Certificate2(cert)), SigningCredentials = new X509SigningCredentials(cert1) }; var […]