I am using the .net FRAMEWORK with ‘UseOktaMvc’ in the middleware. It is authenticating the user and returning the id token and access token, scoped claims are also returned. I have included ‘groups’ in the scope w/o success, no group claims are returned. The groups are active directory groups that are imported into authorization server.
The solution was to decrypt the access_token.
app.Use(async (context, next) =>
{
if (context.Authentication.User.Identity.IsAuthenticated)
{
// Get claims from access_token
var accessToken = ((ClaimsIdentity)context.Authentication.User.Identity).Claims.Where(x => x.Type == "access_token").FirstOrDefault().Value;
var handler = new JwtSecurityTokenHandler();
var token = handler.ReadJwtToken(accessToken);
// Add roles from claims
var claims = new List<Claim>();
foreach (var group in token.Claims.Where(x => x.Type == "allgroups"))
{
claims.Add(new Claim(ClaimTypes.Role, group.Value));
}
if (claims.Count > 0)
{
var identity = new ClaimsIdentity();
identity.AddClaims(claims);
var identities = new List<ClaimsIdentity> { identity };
context.Authentication.User.AddIdentities(identities);
}
}
await next.Invoke();
});