I'd like to allow SAML authentication for my web app, including against AzureAD as an identity provider and also ADFS. (Can anyone point me to a good tutorial or walkthrough on this?) I've got so far as generating the SAML Request, getting back a SAMLP response from AzureAD, and validating its signature (including the fact it's SHA256 which doesn't work by default).
Now I want to extract information from it to verify the issuer and get the user's email to identify them. Is it 'ok' to do this manually via XML or should I use classes like Saml2SecurityTokenHandler? They look like they should do the trick but I find it difficult to understand all the configuration required and whether it's necessary to use such classes from a security point of view.
My app is multi-tenant so I want code rather than configuration to process the Saml as different tenants will use different authentication options.
This blog says to not use ConfigurationBasedIssuerNameRegistry
and instead points to [ValidatingIssuerNameRegistry][3]
. Ok, that seems appropriate for my scenario.
In this question there's some code to programmatically configure a trusted issuer, so I can adjust to use ValidatingIssuerNameRegistry and then presumably I can use tokenHandlers to read the Assertion
from the SAMLP response and then extract the claims including the Name (email). But where do I get the thumbprint & name to pass to it from the AzureAD metadata? And exactly what's the value in using these classes instead of parsing the response myself? It definitely feels like using a library for this is the right thing to do, but the complexity of WIF and lack of walk-through articles on doing this makes it feel like something not appropriate except for those deep in the world of identity.
My guess is if I already have the certificate stored locally to validate the identity of the issuer of the SAML response and I verify the signature in the XML then I can happily use the content of the SAML response. i.e. the user's identity. Still it feels like the wrong approach to do this manually though, but I'm ok with that provided there's no obvious drawbacks.
Some related SO questions & articles: