---
title: Content Delivery API and Azure AD
slug: cms-12/api/content-delivery-api-and-azure-ad
docTags: 
createdAt: 2026-08-07T16:45:43.000Z
---

:::hint{type="info"}
**Note**
This section applies only if you are still using Content Delivery Api v2.x.x. For users using Content Delivery API v3.x.x, see [Authenticate the API](docId\:GcwKCbUQUXLkDILm5DQmW) instead.
:::

First, set up a site using Optimizely Azure AD. See [Integrate Azure AD using OpenID Connect](docId:_pp1SJ3o09ZWliKyqTr27) in the *Optimizely Content Management System (CMS) developer guide*.

Normally, the user information is synchronized with the website by calling `ServiceLocator.Current.GetInstance<ISynchronizingUserService>.SynchronizeAsync(ctx.AuthenticationTicket.Identity)` when using external login systems. You need to customize the initialization process for Content Delivery API to retrieve the roles synced from Azure AD.

- Create the class `CustomInitializationService` which inherits `InitializationService. Override GetAllRoles()`.

```csharp
[ServiceConfiguration(typeof (InitializationService))]
public class CustomInitializationService: InitializationService {
  /// <summary>
  /// Get all roles from system.
  /// </summary>
  protected override IEnumerable<string> GetAllRoles() {
    var synUserRepo = ServiceLocator.Current.GetInstance<ISynchronizedUsersRepository>();
    var rolesStatus = synUserRepo.ListRoleStatus();
    return (rolesStatus != null && rolesStatus.Any()) ? rolesStatus.Select(x => x.Name) : null;
  }
}
```

- Register the class at the initialization module.

```csharp
[InitializableModule]
public class DependencyResolverInitialization: IConfigurableModule {
  public void ConfigureContainer(ServiceConfigurationContext context) {
    //Implementations for custom interfaces can be registered here.
    context.ConfigurationComplete += (o, e) => {
      //Register custom implementations that should be used in favour of the default implementations
      context.Services.AddTransient<IContentRenderer, ErrorHandlingContentRenderer>()
        .AddTransient<ContentAreaRenderer, AlloyContentAreaRenderer>()
        .AddTransient<InitializationService, CustomInitializationService>();
    };
  }
  public void Initialize(InitializationEngine context) {
    DependencyResolver.SetResolver(new ServiceLocatorDependencyResolver(context.Locate.Advanced));
  }
  public void Uninitialize(InitializationEngine context) {}
  public void Preload(string[] parameters) {}
}
```

The code examples here give you the simplest code customizations. For more complicated scenarios, you can customize the class accordingly.
