gpt4 book ai didi

c# - SAML 断言中的 AudienceRestriction

转载 作者:行者123 更新时间:2023-11-30 14:43:53 25 4
gpt4 key购买 nike

谁能给我指出创建一个在条件节点中包含 AudienceRestriction 的 SamlAssertion 的示例的方向?

下面是我想要放置的代码示例:

//Create the SAML Assertion
SamlAssertion samlAssert = new SamlAssertion();
samlAssert.AssertionId = Convert.ToBase64String(encoding.GetBytes(System.Guid.NewGuid().ToString()));
samlAssert.Issuer = "http://www.example.com/";

// Set up the conditions of the assertion - Not Before and Not After
samlAssert.Conditions = new SamlConditions(DateTime.Now, DateTime.Now.AddMinutes(5));

所需的 XML 看起来像这样:

<Assertion xmlns="urn:oasis:names:tc:SAML:1.0:assertion" AssertionID="_e835eca079133299b2f8a2a63ad72fe8" IssueInstant="2007-02-07T20:22:58.165Z" Issuer="http://www.example.com/" MajorVersion="1" MinorVersion="1">
<Conditions NotBefore="2007-02-07T20:22:58.162Z" NotOnOrAfter="2007-02-07T20:24:58.162Z">
<AudienceRestrictionCondition>
<Audience>http://www.example2.com</Audience>
</AudienceRestrictionCondition>
</Conditions>

我看到 SamlConditions 有一个构造函数允许第三个参数的类,条件,并且有一个 SamlAudienceRestriction 类,但我似乎无法弄清楚如何将两者联系起来。我想如果我看到一些代码,它对我来说会变得非常明显,但不幸的是,我的 google-foo 今天让我失望了。

最佳答案

我发誓我在发布之前花了几个小时试图弄清楚这个问题......但显然发布正是我看到答案所需要的。下面是我为 SAML 创建观众限制所做的代码:

//Create the SAML Assertion
SamlAssertion samlAssert = new SamlAssertion();
samlAssert.AssertionId = Convert
.ToBase64String(
encoding.GetBytes(System.Guid.NewGuid().ToString()));
samlAssert.Issuer = "http://www.example.com/";

// Set up the conditions of the assertion - Not Before and Not After
Uri[] approvedAudiences = {new Uri("http://www.example2.com")};
List<SamlCondition> conditions = new List<SamlCondition>();
conditions.Add(new SamlAudienceRestrictionCondition(approvedAudiences));
samlAssert.Conditions = new SamlConditions(
DateTime.Now,
DateTime.Now.AddMinutes(5),
conditions
);

如果有人发现任何错误,或者知道更好/更有效的方法,请告诉我。

关于c# - SAML 断言中的 AudienceRestriction,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1348947/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com