question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Adding XML inside Extensions

See original GitHub issue

I’m trying to create a Saml2AuthnRequest using PostBinding, by following the examples I was able to create the request.

My only problem is that the IdP I’m working with requires me to send a piece of XML inside the Extensions node and when I put the XML as string, the text ends up being encoded

For instance, if I create the Extensions like this…

var extensions = new Extensions()
{
    Data = "<TSP-ID>-</TSP-ID><TSP-TYPE>-</TSP-TYPE>"
}

…the Extensions node ends up being set like the below

<saml2p:Extensions xmlns="urn:oasis:names:tc:SAML:2.0:protocol">&lt;TSP-ID&gt;-&lt;/TSP-ID&gt;&lt;TSP-TYPE&gt;-&lt;/TSP-TYPE&gt;</saml2p:Extensions>

which is not what the IdP expects

I looked at the code in Extensions and I can see the XElement just adds the string (see here)

Is there anyway to add XML in Extensions or this requires a code change in the library?

Thanks

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
Revsgaardcommented, Nov 23, 2021

Thanks for getting back. I have released the support in a beta https://github.com/ITfoxtec/ITfoxtec.Identity.Saml2/releases/tag/4.7.1-beta1

1reaction
Revsgaardcommented, Nov 2, 2021

I have implemented a solution, please take a look at the https://github.com/ITfoxtec/ITfoxtec.Identity.Saml2/commit/d929c88f77a19702e9c914c7a25ffaf96ffe44f1 commit and let me know if it works for you.

The requested XML is added to the TestWebAppCore sample in the AppExtensions.cs. The TestWebAppCore sample should generate the following XML if you uncomment the Extensions = new AppExtensions(), line in AuthController.cs:

<saml2p:AuthnRequest xmlns:saml2p="urn:oasis:names:tc:SAML:2.0:protocol" xmlns:saml2="urn:oasis:names:tc:SAML:2.0:assertion" ID="_6474211f-b7b0-46d4-a0a6-ff256c917b95" Version="2.0" IssueInstant="2021-11-02T20:13:26.447Z" Destination="https://localhost:44305/Auth/Login">
  <saml2:Issuer>itfoxtec-testwebappcore</saml2:Issuer>
  <saml2p:Extensions xmlns:eidas="http://eidas.europa.eu/saml-extensions">
    <eidas:SPType>public</eidas:SPType>
    <eidas:RequestedAttributes>
      <eidas:RequestedAttribute Name="http://eidas.europa.eu/attributes/naturalperson/PersonIdentifier" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:uri" isRequired="false" />
      <eidas:RequestedAttribute Name="http://eidas.europa.eu/attributes/naturalperson/CurrentGivenName" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:uri" isRequired="false" />
      <eidas:RequestedAttribute Name="http://eidas.europa.eu/attributes/naturalperson/CurrentFamilyName" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:uri" isRequired="false" />
      <eidas:RequestedAttribute Name="http://eidas.europa.eu/attributes/naturalperson/CurrentAddress" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:uri" isRequired="false" />
      <eidas:RequestedAttribute Name="http://eidas.europa.eu/attributes/naturalperson/DateOfBirth" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:uri" isRequired="false" />
      <eidas:RequestedAttribute Name="http://eidas.europa.eu/attributes/naturalperson/PlaceOfBirth" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:uri" isRequired="false" />
      <eidas:RequestedAttribute Name="http://www.stork.gov.eu/1.0/countryCodeOfBirth" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:uri" isRequired="false" />
      <eidas:RequestedAttribute Name="http://www.stork.gov.eu/1.0/eMail" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:uri" isRequired="false" />
      <eidas:RequestedAttribute Name="http://www.stork.gov.eu/1.0/age" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:uri" isRequired="false" />
      <eidas:RequestedAttribute Name="http://www.stork.gov.eu/1.0/isAgeOver" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:uri" isRequired="false">
        <eidas:AttributeValue>18</eidas:AttributeValue>
      </eidas:RequestedAttribute>
      <eidas:RequestedAttribute Name="http://schemas.eidentity.cz/moris/2016/identity/claims/phonenumber" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:uri" isRequired="false" />
      <eidas:RequestedAttribute Name="http://schemas.eidentity.cz/moris/2016/identity/claims/tradresaid" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:uri" isRequired="false" />
      <eidas:RequestedAttribute Name="http://schemas.eidentity.cz/moris/2016/identity/claims/idtype" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:uri" isRequired="false" />
      <eidas:RequestedAttribute Name="http://schemas.eidentity.cz/moris/2016/identity/claims/idnumber" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:uri" isRequired="false" />
    </eidas:RequestedAttributes>
  </saml2p:Extensions>
  <saml2:Subject>
    <saml2:NameID>abcd</saml2:NameID>
  </saml2:Subject>
  <saml2p:NameIDPolicy AllowCreate="true" Format="urn:oasis:names:tc:SAML:2.0:nameid-format:persistent" />
</saml2p:AuthnRequest>
Read more comments on GitHub >

github_iconTop Results From Across the Web

Is it possible to add an .XML file in Chrome Extension ...
You can have any data you want in your extension package. All you need is to either expose that file via web_accessible_resources so...
Read more >
Open XML Formats and file name extensions
By default, documents, worksheets, and presentations that you create in Office are saved in XML format with file name extensions that add an...
Read more >
Lesson 5: Modify the plugin.xml file
xml file, select the Extensions tab from the list of tabs at the bottom. Click Add. In the New Extension dialog box that...
Read more >
XML Schema extension Element
The extension element extends an existing simpleType or complexType element. Element Information. Parent elements: simpleContent, complexContent. Syntax. < ...
Read more >
Using XML Extensions in SQL Developer to Extend ...
Now go into the Preferences and add this file to the User Defined Extensions as an 'Action.' Restart SQL Developer and right-click on...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found