Identity Provider Architecture, Part 4: The SAML 2.0 Identity Provider
- Get link
- X
- Other Apps
Many enterprise applications still only speak SAML. The same IdP can serve them from the same sessions and upstream sources, with no second product needed.
Endpoints
| Endpoint | Binding | Purpose |
|---|---|---|
/saml/metadata |
GET | IdP metadata: entity id, signing certificate, SSO and SLO endpoints |
/saml/login |
Redirect or POST in, POST out | Receives an AuthnRequest and returns a Response |
/saml/logout |
Redirect / POST | Single logout |
ITfoxtec.Identity.Saml2 handles the XML, signatures and bindings. The design work is in configuration and claims.
Relying-party configuration
Each SAML application is a SamlRelyingParties row:
| Field | Use |
|---|---|
EntityId |
Must match the Issuer of incoming AuthnRequests |
MetadataUrl |
SP metadata, fetched for ACS URL, signing and encryption certificates |
SignType |
Sign the Response, the Assertion, or both. Apps disagree on this, so make it configurable |
EncryptAssertion |
Encrypt the assertion with the SP's encryption certificate |
NameIdFormat + NameIdSource |
E.g. emailAddress taken from user.email |
SamlUpstreamMappings |
Which upstream login sources this app may use (same broker as OIDC) |
SamlClaimMappings |
Upstream claim → SAML attribute name |
Cache SP metadata and refresh it on a timer. Don't fetch it on every login.
Flow
Building the assertion
var response = new Saml2AuthnResponse(config)
{
InResponseTo = request.Id,
Status = Saml2StatusCodes.Success,
Destination = rp.AcsUrl,
};
var identity = new ClaimsIdentity(MapClaims(session.Claims, rp.ClaimMappings));
response.NameId = new Saml2NameIdentifier(Resolve(rp.NameIdSource, session), rp.NameIdFormat);
response.ClaimsIdentity = identity;
response.CreateSecurityToken(rp.EntityId, subjectConfirmationLifetime: 5, issuedTokenLifetime: 60);
Checklist:
- Use a short
NotOnOrAfteron the subject confirmation (minutes) and a sensible assertion lifetime. - Put
AudienceRestriction= the RP's entity id. - Take the ACS URL from metadata, never from the request alone.
- Pass
RelayStatethrough untouched.
Single logout
SAML single logout is the hardest part of the protocol to get right. Every participant must answer, and browsers block third-party cookies. A pragmatic approach:
- On a
LogoutRequest, end the IdP session and answer with aLogoutResponse. - Use front-channel propagation to other session participants: hidden iframes for OIDC clients that registered a
frontchannel_logout_uri, and redirects for SAML SPs. - Accept that some apps won't be reached. Keep IdP session lifetimes short enough that this is tolerable.
Upstream SAML
The same library makes the IdP a SAML service provider towards an external SAML IdP (Part 5). That needs its own SamlSpConfigs entry (entity id, signing and encryption certificates) and one ExternalSamlIdps row per partner.
- Get link
- X
- Other Apps
Comments