有人可以向我指出创建 SamlAssertion 的示例方向,其中在 Conditions 节点中包含 AudienceRestriction 吗?
下面是我想要放置的代码示例:
//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 今天让我失败了。
Can someone please point me in the direction of an example creating a SamlAssertion that includes an AudienceRestriction in the Conditions node?
below is an example of my code where I would want to put it:
//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));
The desired XML looks something like this:
<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>
I see that there's a constructor for SamlConditions class that allows for a 3rd parameter, the conditions, and that there's a SamlAudienceRestriction class, but I can't seem to figure out how to connect the two. I think if I were to see a bit of code, it would become painfully obvious to me, but unfortunately, my google-foo is failing me today.
发布评论
评论(1)
我发誓我在发帖之前花了几个小时试图弄清楚这个问题......但显然发帖正是我需要看到答案的。下面是我为 SAML 创建受众限制所做的代码:
如果有人发现任何错误,或者知道更好/更有效的方法,请告诉我。
I swear I spent several hours trying to figure this one out before posting...but apparently posting was exactly what I needed to see the answer. Below is the code I did to create the audience restriction for the SAML:
If anyone sees anything wrong, or knows of a better/more efficient way, please let me know.