This guide provides detailed examples and best practices for configuring authentication authorities in Microsoft Entra External ID (formerly CIAM - Customer Identity and Access Management) scenarios using Microsoft.Identity.Web.
Microsoft Entra External ID (CIAM) is a customer identity and access management solution that enables organizations to create secure, customized sign-in experiences for customer-facing applications. CIAM authority configuration has specific requirements, particularly when using custom domains.
| Feature | Traditional Azure AD | CIAM |
|---|---|---|
| Primary Use Case | Employee/organizational identity | Customer/consumer identity |
| Default Domain | login.microsoftonline.com |
{tenant}.ciamlogin.com |
| Custom Domains | Optional | Commonly used for branding |
| Authority Handling | Parsed into Instance + TenantId | Use complete Authority URL |
For CIAM tenants using the default .ciamlogin.com domain:
{
"AzureAd": {
"Authority": "https://contoso.ciamlogin.com/contoso.onmicrosoft.com",
"ClientId": "11111111-1111-1111-1111-111111111111",
"CallbackPath": "/signin-oidc"
}
}Key Points:
- Include the full tenant domain in the Authority
- The library automatically handles CIAM authorities correctly
- Do not mix Authority with Instance/TenantId properties
Custom domains are frequently used in CIAM for seamless brand experience:
{
"AzureAd": {
"Authority": "https://login.contoso.com/contoso.onmicrosoft.com",
"ClientId": "11111111-1111-1111-1111-111111111111",
"CallbackPath": "/signin-oidc"
}
}Important: Ensure your custom domain is properly configured in your CIAM tenant. The library handles custom CIAM domains automatically.
Using the tenant GUID instead of domain name:
{
"AzureAd": {
"Authority": "https://contoso.ciamlogin.com/12345678-1234-1234-1234-123456789012",
"ClientId": "11111111-1111-1111-1111-111111111111"
}
}For CIAM applications supporting multiple customer tenants:
{
"AzureAd": {
"Authority": "https://contoso.ciamlogin.com/common",
"ClientId": "11111111-1111-1111-1111-111111111111",
"ValidateIssuer": false
}
}Warning: Multi-tenant CIAM scenarios require careful issuer validation configuration. Ensure you implement proper tenant isolation in your application logic.
Program.cs (.NET 6+):
using Microsoft.AspNetCore.Authentication.OpenIdConnect;
using Microsoft.Identity.Web;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddAuthentication(OpenIdConnectDefaults.AuthenticationScheme)
.AddMicrosoftIdentityWebApp(options =>
{
builder.Configuration.Bind("AzureAd", options);
});
builder.Services.AddAuthorization();
builder.Services.AddRazorPages();
var app = builder.Build();
// Configure the HTTP request pipeline
app.UseAuthentication();
app.UseAuthorization();
app.MapRazorPages();
app.Run();builder.Services.AddAuthentication(OpenIdConnectDefaults.AuthenticationScheme)
.AddMicrosoftIdentityWebApp(options =>
{
builder.Configuration.Bind("AzureAd", options);
options.Events = new OpenIdConnectEvents
{
OnRedirectToIdentityProvider = context =>
{
// Add custom parameters if needed
context.ProtocolMessage.SetParameter("ui_locales", "en-US");
return Task.CompletedTask;
},
OnTokenValidated = context =>
{
// Custom validation logic
var tenantId = context.Principal?.FindFirst("tid")?.Value;
// Implement tenant-specific logic
return Task.CompletedTask;
}
};
});To use custom domains with CIAM, configure your tenant:
- Navigate to Microsoft Entra admin center
- Select your CIAM tenant
- Go to Custom domains
- Add and verify your custom domain (e.g.,
login.contoso.com) - Configure DNS CNAME records as instructed
{
"AzureAd": {
"Authority": "https://login.contoso.com/{tenant-id-or-domain}",
"ClientId": "your-client-id",
"CallbackPath": "/signin-oidc"
}
}In your app registration, add redirect URIs using the custom domain:
https://yourapp.com/signin-oidchttps://yourapp.com/signout-callback-oidc
Configuring both Authority and Instance/TenantId throws an InvalidOperationException at startup.
Wrong (throws at startup):
{
"AzureAd": {
"Authority": "https://contoso.ciamlogin.com/contoso.onmicrosoft.com",
"Instance": "https://contoso.ciamlogin.com/",
"TenantId": "contoso.onmicrosoft.com",
"ClientId": "11111111-1111-1111-1111-111111111111"
}
}Correct: Use only Authority:
{
"AzureAd": {
"Authority": "https://contoso.ciamlogin.com/contoso.onmicrosoft.com",
"ClientId": "11111111-1111-1111-1111-111111111111"
}
}Wrong:
{
"AzureAd": {
"Authority": "https://login.microsoftonline.com/contoso.onmicrosoft.com",
"ClientId": "11111111-1111-1111-1111-111111111111"
}
}Correct: Use the CIAM-specific domain:
{
"AzureAd": {
"Authority": "https://contoso.ciamlogin.com/contoso.onmicrosoft.com",
"ClientId": "11111111-1111-1111-1111-111111111111"
}
}Organizations migrating from Azure AD B2C to CIAM should note key differences:
{
"AzureAdB2C": {
"Authority": "https://contoso.b2clogin.com/contoso.onmicrosoft.com/B2C_1_susi",
"ClientId": "11111111-1111-1111-1111-111111111111",
"Domain": "contoso.onmicrosoft.com",
"SignUpSignInPolicyId": "B2C_1_susi"
}
}{
"AzureAd": {
"Authority": "https://contoso.ciamlogin.com/contoso.onmicrosoft.com",
"ClientId": "22222222-2222-2222-2222-222222222222"
}
}Key Differences:
- CIAM doesn't use policy IDs in the Authority
- CIAM uses
AzureAdconfiguration section (notAzureAdB2C) - The library automatically handles CIAM authorities
- No need for
Domainproperty unless specific scenarios require it
{
"AzureAd": {
"Authority": "https://contoso-dev.ciamlogin.com/contoso-dev.onmicrosoft.com",
"ClientId": "dev-client-id",
"CallbackPath": "/signin-oidc"
}
}{
"AzureAd": {
"Authority": "https://login.contoso.com/contoso.onmicrosoft.com",
"ClientId": "prod-client-id",
"CallbackPath": "/signin-oidc"
}
}Use separate configuration files:
appsettings.Development.jsonappsettings.Staging.jsonappsettings.Production.json
- Check Authority Format: Ensure it uses CIAM domain (
.ciamlogin.comor custom domain) - Avoid mixing: Using both Authority and Instance/TenantId throws
InvalidOperationException - Test Sign-in Flow: Verify authentication redirects work correctly
- Monitor Logs: Check for any configuration errors at startup
Issue: "The reply URL specified does not match"
- Cause: Redirect URI mismatch between app configuration and Azure registration
- Fix: Ensure CallbackPath matches Azure app registration redirect URIs
Issue: "AADSTS50011: The reply URL does not match"
- Cause: Custom domain not properly configured
- Fix: Verify custom domain DNS settings and Azure CIAM configuration
Issue: Authority configuration errors
- Cause: Mixing Authority with Instance/TenantId
- Fix: Use Authority only for CIAM. Mixing throws
InvalidOperationExceptionat startup
Protecting a Web API with CIAM:
// Program.cs for Web API
builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddMicrosoftIdentityWebApi(options =>
{
builder.Configuration.Bind("AzureAd", options);
},
options =>
{
builder.Configuration.Bind("AzureAd", options);
});builder.Services.AddAuthentication(OpenIdConnectDefaults.AuthenticationScheme)
.AddMicrosoftIdentityWebApp(options =>
{
builder.Configuration.Bind("AzureAd", options);
})
.EnableTokenAcquisitionToCallDownstreamApi(
builder.Configuration.GetSection("DownstreamApi:Scopes").Get<string[]>())
.AddInMemoryTokenCaches();
builder.Services.AddDownstreamApi("DownstreamApi",
builder.Configuration.GetSection("DownstreamApi"));