Skip to content
Branch: master
Find file Copy path
Find file Copy path
1 contributor

Users who have contributed to this file

41 lines (36 sloc) 1.58 KB
// Copyright (c) 2019 Jon P Smith, GitHub: JonPSmith, web:
// Licensed under MIT license. See License.txt in the project root for license information.
using System.Security.Claims;
using System.Threading.Tasks;
using DataAuthorize;
using DataKeyParts;
using DataLayer.EfCode;
using FeatureAuthorize;
using Microsoft.AspNetCore.Identity;
using Microsoft.Extensions.Options;
namespace AuthorizeSetup
/// <summary>
/// This version provides:
/// - Adds Permissions to the user's claims.
/// </summary>
// Thanks to
public class AddPermissionsToUserClaims : UserClaimsPrincipalFactory<IdentityUser>
private readonly ExtraAuthorizeDbContext _extraAuthDbContext;
public AddPermissionsToUserClaims(UserManager<IdentityUser> userManager, IOptions<IdentityOptions> optionsAccessor,
ExtraAuthorizeDbContext extraAuthDbContext)
: base(userManager, optionsAccessor)
_extraAuthDbContext = extraAuthDbContext;
protected override async Task<ClaimsIdentity> GenerateClaimsAsync(IdentityUser user)
var identity = await base.GenerateClaimsAsync(user);
var userId = identity.Claims.GetUserIdFromClaims();
var rtoPCalcer = new CalcAllowedPermissions(_extraAuthDbContext);
identity.AddClaim(new Claim(PermissionConstants.PackedPermissionClaimType, await rtoPCalcer.CalcPermissionsForUserAsync(userId)));
return identity;
You can’t perform that action at this time.