After a lot of digging I found what the issue was for us and some of these answers are correct but only if you have not configured your App Service to have Azure AD enabled.
If you do this the RoleClaimType defined in code will not be used and it will set it to the default of "http://schemas.microsoft.com/ws/2008/06/identity/claims/role", but all your role claims will be "roles".
The solution is to basically copy the claims from "roles" to the ClaimsIdentity.RoleClaimType. The solution was found here and mentioned above.
Solution:
public void ConfigureAuth(IAppBuilder app)
{
//This setting ensures that we use the specified TokenValidationParameters.RoleClaimType below
JwtSecurityTokenHandler.DefaultMapInboundClaims = false;
app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);
app.UseCookieAuthentication(new CookieAuthenticationOptions());
app.UseOpenIdConnectAuthentication(
new OpenIdConnectAuthenticationOptions
{
//Omitted some stuff
TokenValidationParameters = new TokenValidationParameters()
{
ValidateIssuer = true,
RoleClaimType = "roles"
}
}
);
//Configure out OnAuth Method to fix the roles post auth
app.Use((context, next) =>
{
OnAuth(context);
return next.Invoke();
});
app.UseStageMarker(PipelineStage.PostAuthenticate);
}
private static void OnAuth(IOwinContext context)
{
if (ClaimsPrincipal.Current.Identity.IsAuthenticated)
{
var claimsPrincipal = ClaimsPrincipal.Current;
var claimsIdentity = claimsPrincipal.Identity as ClaimsIdentity;
var appRoles = new List<Claim>();
//local dev will be right
if (claimsIdentity.RoleClaimType == "roles")
return;
//Find all the claims with "roles" and add a copy claim with the correct RoleClaimType.
foreach (Claim claim in claimsPrincipal.FindAll("roles"))
appRoles.Add(new Claim(claimsIdentity.RoleClaimType, claim.Value));
if (appRoles.Count > 0)
claimsIdentity.AddClaims(appRoles);
}
}