当前位置: 首页>>代码示例>>C#>>正文


C# ClaimsIdentity.ToSaml2Assertion方法代码示例

本文整理汇总了C#中System.Security.Claims.ClaimsIdentity.ToSaml2Assertion方法的典型用法代码示例。如果您正苦于以下问题:C# ClaimsIdentity.ToSaml2Assertion方法的具体用法?C# ClaimsIdentity.ToSaml2Assertion怎么用?C# ClaimsIdentity.ToSaml2Assertion使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Security.Claims.ClaimsIdentity的用法示例。


在下文中一共展示了ClaimsIdentity.ToSaml2Assertion方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ClaimsIdentityExtensions_ToSaml2Assertion_ThrowsOnNullIssuer

        public void ClaimsIdentityExtensions_ToSaml2Assertion_ThrowsOnNullIssuer()
        {
            var subject = new ClaimsIdentity();

            Action a = () => subject.ToSaml2Assertion(null);

            a.ShouldThrow<ArgumentNullException>().And.ParamName.Should().Be("issuer");
        }
开发者ID:Raschmann,项目名称:authservices,代码行数:8,代码来源:ClaimsIdentityExtensionsTests.cs

示例2: ClaimsIdentityExtensions_ToSaml2Assertion_Includes_DefaultCondition

        public void ClaimsIdentityExtensions_ToSaml2Assertion_Includes_DefaultCondition()
        {
            var ci = new ClaimsIdentity(new Claim[] { 
                new Claim(ClaimTypes.NameIdentifier, "JohnDoe")
            });

            var a = ci.ToSaml2Assertion(new EntityId("http://idp.example.com"));

            // Default validity time is hearby defined to two minutes.
            a.Conditions.NotOnOrAfter.Value.Should().BeCloseTo(DateTime.UtcNow.AddMinutes(2));
        }
开发者ID:Raschmann,项目名称:authservices,代码行数:11,代码来源:ClaimsIdentityExtensionsTests.cs

示例3: ClaimsIdentityExtensions_ToSaml2Assertion_Includes_Attributes

        public void ClaimsIdentityExtensions_ToSaml2Assertion_Includes_Attributes()
        {
            var ci = new ClaimsIdentity(new Claim[] { 
                new Claim(ClaimTypes.NameIdentifier, "JohnDoe"),
                new Claim(ClaimTypes.Role, "Test")
            });

            var a = ci.ToSaml2Assertion(new EntityId("http://idp.example.com"));

            a.Statements.SingleOrDefault().Should().BeOfType<Saml2AttributeStatement>();
            (a.Statements.SingleOrDefault() as Saml2AttributeStatement).Attributes[0].Values[0].Should().Be("Test");
        }
开发者ID:Raschmann,项目名称:authservices,代码行数:12,代码来源:ClaimsIdentityExtensionsTests.cs

示例4: ClaimsIdentityExtensions_ToSaml2Assertion_Includes_Subject

        public void ClaimsIdentityExtensions_ToSaml2Assertion_Includes_Subject()
        {
            var subject = "JohnDoe";

            var ci = new ClaimsIdentity(new Claim[] { 
                new Claim(ClaimTypes.NameIdentifier, subject)
            });

            var a = ci.ToSaml2Assertion(new EntityId("http://idp.example.com"));

            a.Subject.NameId.Value.Should().Be(subject);
        }
开发者ID:Raschmann,项目名称:authservices,代码行数:12,代码来源:ClaimsIdentityExtensionsTests.cs

示例5: ClaimsIdentityExtensions_ToSaml2Assertion_MultipleValuesForSameKey_CombinesTo_OneAttribute

        public void ClaimsIdentityExtensions_ToSaml2Assertion_MultipleValuesForSameKey_CombinesTo_OneAttribute()
        {
            var ci = new ClaimsIdentity(new Claim[] { 
                new Claim(ClaimTypes.NameIdentifier, "JohnDoe"),
                new Claim(ClaimTypes.Role, "Test1"),
                new Claim(ClaimTypes.Role, "Test2"),
            });

            var a = ci.ToSaml2Assertion(new EntityId("http://idp.example.com"));

            a.Statements.SingleOrDefault().Should().BeOfType<Saml2AttributeStatement>();
            (a.Statements.SingleOrDefault() as Saml2AttributeStatement).Attributes[0].Values[0].Should().Be("Test1");
            (a.Statements.SingleOrDefault() as Saml2AttributeStatement).Attributes[0].Values[1].Should().Be("Test2");
        }
开发者ID:arvinsuresh,项目名称:authservices,代码行数:14,代码来源:ClaimsIdentityExtensionsTests.cs

示例6: ClaimsIdentityExtensions_ToSaml2Assertion_Includes_Attributes

        public void ClaimsIdentityExtensions_ToSaml2Assertion_Includes_Attributes()
        {
            var ci = new ClaimsIdentity(new Claim[] {
                new Claim(ClaimTypes.NameIdentifier, "JohnDoe"),
                new Claim(ClaimTypes.Role, "Test"),
                new Claim(ClaimTypes.Email, "[email protected]"),
            });

            var actual = ci.ToSaml2Assertion(new EntityId("http://idp.example.com"));

            actual.Statements.OfType<Saml2AttributeStatement>().Should().HaveCount(1);
            actual.Statements.OfType<Saml2AttributeStatement>().Single().Attributes[0].Values[0].Should().Be("Test");
            actual.Statements.OfType<Saml2AttributeStatement>().Single().Attributes[1].Values[0].Should().Be("[email protected]");
        }
开发者ID:crixo,项目名称:authservices,代码行数:14,代码来源:ClaimsIdentityExtensionsTests.cs

示例7: ClaimsIdentityExtensions_ToSaml2Assertion_Includes_AudienceRestriction

        public void ClaimsIdentityExtensions_ToSaml2Assertion_Includes_AudienceRestriction()
        {
            var ci = new ClaimsIdentity(new Claim[] {
                new Claim(ClaimTypes.NameIdentifier, "JohnDoe")
            });

            var audience = "http://sp.example.com/";

            var a = ci.ToSaml2Assertion(
                new EntityId("http://idp.example.com/"),
                new Uri(audience));

            a.Conditions.AudienceRestrictions.Should().HaveCount(1, "there should be one set of audience restrictions")
                .And.Subject.Single().Audiences.Should().HaveCount(1, "there should be one allowed audience")
                .And.Subject.Single().AbsoluteUri.Should()
                .Be("http://sp.example.com/");
        }
开发者ID:CDHDeveloper,项目名称:authservices,代码行数:17,代码来源:ClaimsIdentityExtensionsTests.cs

示例8: ClaimsIdentityExtensions_ToSaml2Assertion_MultipleValuesForSameKey_CombinesTo_OneAttribute

        public void ClaimsIdentityExtensions_ToSaml2Assertion_MultipleValuesForSameKey_CombinesTo_OneAttribute()
        {
            var ci = new ClaimsIdentity(new Claim[] {
                new Claim(ClaimTypes.NameIdentifier, "JohnDoe"),
                new Claim(ClaimTypes.Role, "Test1"),
                new Claim(ClaimTypes.Role, "Test2"),
            });

            var assertion = ci.ToSaml2Assertion(new EntityId("http://idp.example.com"));

            assertion.Statements.OfType<Saml2AttributeStatement>().Should().HaveCount(1);
            var actual = assertion.Statements.OfType<Saml2AttributeStatement>().Single();

            var expected = new Saml2AttributeStatement(
                new Saml2Attribute(ClaimTypes.Role, new[] { "Test1", "Test2" }));

            actual.ShouldBeEquivalentTo(expected);
        }
开发者ID:crixo,项目名称:authservices,代码行数:18,代码来源:ClaimsIdentityExtensionsTests.cs

示例9: ClaimsIdentityExtensions_ToSaml2Assertion_Sets_SessionIndex

        public void ClaimsIdentityExtensions_ToSaml2Assertion_Sets_SessionIndex()
        {
            var subject = new ClaimsIdentity(new Claim[] {
                new Claim(ClaimTypes.NameIdentifier, "NameId"),
                new Claim(AuthServicesClaimTypes.SessionIndex, "SessionID"),
                new Claim(ClaimTypes.Email, "[email protected]")
            });

            var issuer = new EntityId("http://idp.example.com");
            var actual = subject.ToSaml2Assertion(issuer);

            actual.Statements.OfType<Saml2AuthenticationStatement>()
                .Single().SessionIndex.Should().Be("SessionID");

            var attributes = actual.Statements.OfType<Saml2AttributeStatement>()
                .Single().Attributes;

            attributes.Should().HaveCount(1);

            attributes.Single().ShouldBeEquivalentTo(
                new Saml2Attribute(ClaimTypes.Email, "[email protected]"));
        }
开发者ID:johansvard,项目名称:authservices,代码行数:22,代码来源:ClaimsIdentityExtensionsTests.cs


注:本文中的System.Security.Claims.ClaimsIdentity.ToSaml2Assertion方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。