By ··9 min read

Optimizely CMS 12 OpenID Connect: why the edit UI returns 403

Signing in works but the CMS edit UI says 403. How a role travels from an identity provider group to a CMS check, five fixes that did nothing, and a local-only claim that works.

I signed in to a local Optimizely CMS 12 site and opened the edit UI, which this project serves at /admui (the default path is /episerver). The browser did not show a page from the site. It showed this:

Access to localhost was denied
You don't have the user rights to view this page.

That is a 403, and it is a different problem from a redirect to the sign-in page. A redirect means you are not signed in. A 403 means you are signed in and the app has decided you may not come in.

How a role gets from the identity provider to a CMS check

OIDC is a standard sign-in protocol: the site sends you to an identity provider, you sign in there, and the provider sends back an id_token, a signed bundle of facts about you. A claim is one of those facts, such as GroupNames or an email address. A principal is the signed-in user as ASP.NET Core sees it: a list of claims. A role is a claim of type ClaimTypes.Role, and IsInRole("WebAdmins") looks for a role claim with that value.

The path has five stops. This is the code on the project I worked on, in generic form.

Five stages from the identity provider to the CMS: the provider sends an id_token, the OIDC handler runs claim actions, the cookie SigningIn event runs, the cookie is written, and the SignedIn event syncs roles to the CMS. The claim action stage is marked as where the local role claim worked; dead ends are marked beside the stages they targeted.
The claim action stage is where my local role claim worked. The red notes are where my other attempts landed.
  1. The identity provider sends an id_token with the user’s groups.
  2. The OIDC handler validates the id_token, builds an identity from its claims, then runs the claim actions registered in options.ClaimActions. A claim action is a small class with a Run method that can add claims. The project registered two, and both turned group claims already on the identity into role claims.
  3. The cookie handler fires SigningIn, builds the ticket (the principal plus sign-in details, encrypted into the cookie) and writes the cookie.
  4. SignedIn fires after the cookie is written. The project used it to call Optimizely’s synchronising user service, as Optimizely’s own OIDC guide does. That service copies the user and their role claims into the CMS database (tblSynchedUser, tblSynchedUserRole, tblSynchedUserRelations), so they are available to the CMS.
  5. Access checks read the role claims on the principal. Getting into the edit UI needs an editor or admin role. Each content item then has its own access rights, stored as rows of role name plus a permission mask in tblContentAccess:
fkContentID Name IsRole AccessMask
1 Administrators 1 63
1 Everyone 1 1
1 WebEditors 1 1

The mask bits are Read=1, Create=2, Edit=4, Delete=8, Publish=16, Administer=32. If none of your role claims match a row, you have no rights on that item.

What was wrong

The sign-in worked, so stops 1 to 3 had at least run. I needed to see what was on my principal. The project already had a text route for that, and the minimal version is short:

Controllers/WhoamiController.cs
public class WhoamiController : Controller
{
[Authorize]
[Produces("text/plain")]
[Route("/whoami")]
public IActionResult Index()
{
var claims = User.Claims
.OrderBy(c => c.Type)
.Select(c => $" - {c.Type}: {c.Value}");
return Ok($"IsAuthenticated: {User.Identity?.IsAuthenticated}\nClaims:\n{string.Join("\n", claims)}");
}
}

The project’s own version printed roles through its own user-information service. This is what it printed for me:

IsAuthenticated: True
Authentication type: AuthenticationTypes.Federation
Roles:
- Role: Authenticated
- Role: Everyone

Two roles, both given to every signed-in user. No editor role, so no way into the edit UI. The proper fix is for my group membership at the identity provider to be corrected, which is a request to whoever owns the groups. I wanted to work in the meantime, so I tried to add roles myself.

Five fixes that did nothing

These attempts did not happen in one sitting. They come from three separate times over about six weeks: the first in July, getting into the edit UI at all; the second a month later, needing admin rights; the third two weeks after that, testing a feature with extra roles. Each failed for a reason worth knowing.

1. An IClaimsTransformation (July). ASP.NET Core lets you register a class that adds claims on every request. I registered one that added the CMS roles in Development, rebuilt, and /whoami still showed two roles.

My first explanation was that Optimizely registers its own transformation and mine was shadowed. I did not confirm that. A search found no other IClaimsTransformation in the project code, and I never inspected the Optimizely packages. What the evidence proves is narrower: in that app, my transformation did not change what /whoami printed.

A small middleware placed right after app.UseAuthentication() did add the roles, and the edit UI loaded. That solved my problem. It did not explain the transformation.

2. Editing GroupMapping (August). The project has configuration that maps identity provider groups to roles:

appsettings.Development.json
{
"ConfigSection": {
"OidcSiteSettings": {
"GroupMapping": [
{ "GroupNameStartingWith": "Idp-Editors", "MapToGroups": [ "WebEditors" ] },
{ "GroupNameStartingWith": "Idp-Admins", "MapToGroups": [ "WebAdmins", "Administrators" ], "PassThrough": false }
]
}
}
}

I added an entry with an empty prefix, since every string starts with "", and restarted. Nothing changed. Both the source and the copied bin settings file held my edit, so the file was in place. The class that reads this config is PropertyToRolesClaimAction, and it was never registered. The project’s OIDC setup added only the two claim actions that read group claims:

Infrastructure/Extensions/OidcServiceCollectionExtensions.cs
var rolesClaimActions = new ClaimAction[]
{
new GroupNamesClaimToRolesAction(),
new OtherGroupsClaimToRolesAction() // reads a second group claim
};
// ...
foreach (var action in rolesClaimActions)
{
options.ClaimActions.Add(action);
}

PropertyToRolesClaimAction lived in the code base with its own unit tests, so it looked live. At the time I blamed its early return instead:

Infrastructure/Claims/PropertyToRolesClaimAction.cs
public override void Run(JsonElement userData, ClaimsIdentity identity, string issuer)
{
if (!userData.TryGetProperty(this.groupsPropertyName, out JsonElement memberOfElement))
{
return; // no "memberof" in userData, so GroupMapping is never evaluated
}
// ...match each group against GroupMapping, add role claims
}

userData is meant to be the JSON from the provider’s userinfo endpoint, a URL that returns more facts about the user. That early return would also have stopped it, as fix 4 shows. But the first reason is simpler: config that no registered code reads does nothing.

3. Roles cached in the database (August). My account already held two editor roles that no mapping explained, so I decided they were cached rows in the sync tables and inserted two admin roles for my user. /whoami did not change.

Those tables are written from claims at sign-in (stop 4), and nothing in this app copied them back onto the principal. My “cached rows” explanation was wrong. The roles I held came from the claim action that reads GroupNames.

4. GetClaimsFromUserInfoEndpoint = false, so claim actions never run (late August). I needed extra roles to test a feature. I put them in a claim action, saw no effect, and found GetClaimsFromUserInfoEndpoint = false in the OIDC options. That option tells the handler not to call the userinfo endpoint. I concluded the claim actions were dead code.

That was wrong too. In the ASP.NET Core 8 source, the handler’s else branch runs every claim action anyway, against an empty JSON document:

OpenIdConnectHandler.cs (dotnet/aspnetcore, release/8.0)
if (Options.GetClaimsFromUserInfoEndpoint)
{
return await GetUserInformationAsync(/* ... */);
}
else
{
using (var payload = JsonDocument.Parse("{}"))
{
var identity = (ClaimsIdentity)user!.Identity!;
foreach (var action in Options.ClaimActions)
{
action.Run(payload.RootElement, identity, ClaimsIssuer);
}
}
}

So a claim action that reads userData gets {} and does nothing. A claim action that reads claims already on the identity, such as GroupNames from the id_token, works fine. Both of this project’s registered actions were the second kind.

5. OnSignedIn (late August). I added my role claims in the SignedIn handler, next to the sync call. Signing out and in changed nothing, even though the sync timestamp proved the handler ran. In the ASP.NET Core cookie handler, SigningIn is awaited before the ticket is protected into the cookie, and SignedIn after. A claim added at stop 4 changes an identity that is already serialised.

I moved the line to SigningIn, and the roles still did not show up. I never found out why. I may not have signed in again after that rebuild.

What showed the truth

In that third round, the debugger did, once I stopped guessing. With a breakpoint in the code that checked the roles, I listed the role claims and the distinct claim types in the Immediate window:

principal.Claims.Where(c => c.Type == ClaimTypes.Role).Select(c => c.Value).ToList()
Count = 16 // WebAdmins, Administrators, WebEditors, CmsAdmins, ...
principal.Claims.Select(c => c.Type).Distinct().ToList()
[6]: "GroupNames"
[18]: "http://schemas.microsoft.com/ws/2008/06/identity/claims/role"

GroupNames had arrived and sixteen role claims were on the ticket. The pipeline was healthy. The roles I was testing with were names I had made up, which the identity provider never sent. Config and database edits could never have created them, and none of my sign-in hook attempts had put them on the ticket either.

Three episodes over six weeks: a 403 on the edit UI in July, a /whoami page showing only Authenticated and Everyone, config and database edits in August that did nothing, the debugger in late August listing the role claims, and the cause: the test roles were never sent.
Each time, looking at the principal moved things on. Changing config without looking did not.

The fix, for local work only

For my own machine, the smallest change that worked was one role claim added inside a claim action, a stage that runs before the cookie is written. On the project, that line went into the base class both registered claim actions share. This is the shape, with the environment guard I would add:

Infrastructure/Claims/ClaimActionBase.cs
public override void Run(JsonElement userData, ClaimsIdentity identity, string issuer)
{
// LOCAL DEV ONLY - DO NOT COMMIT
if (Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") == "Development")
{
identity.AddClaim(new Claim(ClaimTypes.Role, "WebAdmins"));
}
var claims = identity.Claims.Where(c => c.Type == this.claimNameContainingRoles);
// ... existing code that turns those claims into role claims
}

Sign out and back in, because claim actions only run at sign-in and a role claim only lands in a new cookie. Open /whoami and check that WebAdmins is listed, then open the edit UI.

Takeaways

  • A 403 after sign-in means the principal lacks a role, not that you are signed out.
  • Print the claims first, with /whoami or the debugger. Do not change config until you know which role is missing.
  • Check options.ClaimActions to see which claim actions really run. Config read by an unregistered class does nothing.
  • With GetClaimsFromUserInfoEndpoint = false, claim actions still run, on an empty JSON document. Actions that read existing claims keep working.
  • Add claims before the cookie is written. SignedIn is too late, and the sync tables are an output, not a source.
  • A local role claim is a workaround. Guard it, keep it local, mark it, and ask for the real group.