Serializing Options into JSON
The JSON representation of authentication handler options depends on the version of the library you are using. Serializing the options into JSON yourself gives you greater flexibility and is less error-prone for complex property values such as X509 certificates. You can generate the JSON once and use that as a template.
To serialize authentication handler options into JSON, we recommend using Newtonsoft.Json with our converters. For example:
JsonSerializerSettings settings = new JsonSerializerSettings
{
NullValueHandling = NullValueHandling.Ignore,
ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
Converters =
{
new X509Certificate2Converter(),
// SAML
new SamlEndpointConverter(),
new Saml2pAuthenticationOptionsConverter(),
// OIDC
new OpenIdConnectOptionsConverter(),
// WS-Fed
// new WsFederationOptionsConverter()
}
};
var options = new Saml2pAuthenticationOptions
{
ServiceProviderOptions = new SpOptions
{
EntityId = "http://localhost:5001",
EncryptionCertificate = new X509Certificate2("Resources/idsrv3test.cer"),
SigningCertificate = new X509Certificate2("Resources/idsrv3test.cer")
},
IdentityProviderOptions = new IdpOptions
{
EntityId = "http://localhost:5000",
SingleSignOnEndpoint = new SamlEndpoint("http://localhost:5000/saml/sso", SamlBindingTypes.HttpPost),
SigningCertificates = new List<X509Certificate2> { new X509Certificate2("Resources/idsrv3test.cer") }
},
MessageTrustLength = TimeSpan.FromMinutes(10),
TimeComparisonTolerance = 100,
SignInScheme = "cookie",
CallbackPath = "/signin",
// ....
};
var json = JsonConvert.SerializeObject(options, settings);
Previous
Next