How do I create custom field/values with Low-level api AuthnRequest.Extensions

I’m trying to pass a custom attribute with my request from SP to IDP request. e.g. field: MyCustomAttribue value:123.

I’m stuck here…
Snippet//authnRequest.Extensions = new Extensions(…

How do I create the extensions XML Element with my custom attribute>

Thanks

Generally you’re better off not using extensions as this will limit interoperability.
If you have to use an extension then simply construct the extensions XML and pass this into the Extensions constructor.

// Construct the extension XML - details not shown.
XmlElement xmlElement = …

// Create the SAML extensions and add it to the authn request.
authnRequest.Extensions = new Extensions(xmlElement);

In case it helps anyone, this is how to add the extensions:

AuthnRequest authnRequest = new AuthnRequest();var doc = new XmlDocument();doc.LoadXml("123");authnRequest.Extensions = new Extensions();authnRequest.Extensions.Data = doc.ChildNodes;