Skip to main content

Authentication & Authorization

The Admin API uses Microsoft Entra ID (Azure AD) for authentication via JWT bearer tokens, integrated through the Microsoft.Identity.Web library.

Authentication Flow​

Configuration​

Authentication is configured in Program.cs using the AzureAdAdmin configuration section:

builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddMicrosoftIdentityWebApi(azureConfig, "AzureAdAdmin", "Bearer");

The AzureAdAdmin section is loaded from Azure App Configuration and contains the tenant ID, client ID, and audience for token validation.

Role-Based Authorization​

Controllers use the [Authorize] attribute with role requirements:

RoleAccess Level
Admin.GlobalFull administrative access β€” all operations
Admin.ReadWriteRead and write access to camera configuration

Roles are assigned in Microsoft Entra ID and included as claims in the JWT token.

Managed Identity​

The API uses DefaultAzureCredential for secure access to Azure services without storing credentials:

  • Azure App Configuration β€” Connection via managed identity
  • Key Vault β€” Secrets accessed through App Configuration key vault references
  • Cosmos DB, SQL, Storage β€” All accessed via managed identity in deployed environments

CORS​

CORS is configured to allow the React development server:

policy.WithOrigins("http://localhost:3000")
.AllowAnyHeader()
.AllowAnyMethod()
.AllowCredentials();

In production, the React SPA is served as static files directly from the API, so CORS is not needed.

Authorization Endpoints​

The AuthorizationController provides:

EndpointMethodPurpose
/authorization/loginGETRedirects to Entra ID login, returns access token
/authorization/tokenGETReturns a token for the current session

These endpoints are primarily used by Swagger UI to authenticate interactively.