Course contentsShow
← C#
Lesson 1239 of 1,90811. Identity, Security, and ClaimsFree lesson

Cross-Domain Identity Federation

Use SAML or OIDC to federate identities across different enterprise domains.

In this lesson, you will learn how to enable users to access resources across different enterprise domains using identity federation protocols like OIDC and SAML.

The Problem: Identity Silos

In a large enterprise, different departments or partner organizations often manage their own independent Identity Providers (IdPs). If "Domain A" needs to access a web API hosted in "Domain B," you don't want to recreate every user account in Domain B. Instead, you use Identity Federation, which establishes a trusted relationship between the two domains.

How Federation Works

Federation relies on a "Trust Relationship." When a user from Domain A attempts to access an application in Domain B, the application redirects the user to their home domain (Domain A) to authenticate.

  1. The Request: The application in Domain B (the Service Provider) generates an authentication request.
  2. The Handshake: The user authenticates at Domain A.
  3. The Token: Domain A issues a signed token (a JWT for OIDC or an XML Assertion for SAML) back to the user, which they present to Domain B.
  4. Validation: Domain B verifies the signature using the public key of Domain A to confirm the user’s identity without ever seeing their password.

Implementing with OpenID Connect (OIDC)

In C#, you typically configure this in your Program.cs or Startup.cs using the AddAuthentication middleware. By pointing your OIDC configuration to the remote provider, the underlying library handles the cryptographic validation automatically:

builder.Services.AddAuthentication(options => {
    options.DefaultScheme = "Cookies";
    options.DefaultChallengeScheme = "oidc";
})
.AddCookie()
.AddOpenIdConnect("oidc", options => {
    options.Authority = "https://identity-domain-a.com"; // The trusted external IdP
    options.ClientId = "my-enterprise-app";
    options.ClientSecret = "secure-secret";
    options.ResponseType = "code";
});

By setting the Authority, your application trusts tokens signed by that external domain. This architecture allows you to scale access across organizational boundaries without managing local credentials, effectively treating external users as first-class citizens in your own authorization policies.

Key Takeaway: Cross-domain identity federation eliminates the need for redundant user management by establishing a trust relationship where your application validates tokens issued by an external, authoritative Identity Provider.