Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rename ApplicationUserClaimsPrincipalFactory #524

Merged
merged 1 commit into from
Oct 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public static IServiceCollection AddAuthenticationService(this IServiceCollectio
services
.AddIdentity<ApplicationUser, ApplicationRole>()
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddClaimsPrincipalFactory<ApplicationUserClaimsPrincipalFactory>()
.AddDefaultTokenProviders();
services.Configure<IdentityOptions>(options =>
{
Expand All @@ -42,7 +43,7 @@ public static IServiceCollection AddAuthenticationService(this IServiceCollectio
options.User.RequireUniqueEmail = true;

});
services.AddScoped<IUserClaimsPrincipalFactory<ApplicationUser>, ApplicationClaimsIdentityFactory>()
services
.AddScoped<IIdentityService, IdentityService>()
.AddAuthorization(options =>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@

namespace CleanArchitecture.Blazor.Infrastructure.Services;
#nullable disable
public class ApplicationClaimsIdentityFactory : UserClaimsPrincipalFactory<ApplicationUser, ApplicationRole>
public class ApplicationUserClaimsPrincipalFactory : UserClaimsPrincipalFactory<ApplicationUser, ApplicationRole>
{
private readonly UserManager<ApplicationUser> _userManager;

public ApplicationClaimsIdentityFactory(UserManager<ApplicationUser> userManager,

public ApplicationUserClaimsPrincipalFactory(UserManager<ApplicationUser> userManager,
RoleManager<ApplicationRole> roleManager,
IOptions<IdentityOptions> optionsAccessor) : base(userManager, roleManager, optionsAccessor)
{
_userManager = userManager;

}
public override async Task<ClaimsPrincipal> CreateAsync(ApplicationUser user)
{
Expand Down Expand Up @@ -48,8 +48,8 @@ public override async Task<ClaimsPrincipal> CreateAsync(ApplicationUser user)
new Claim(ApplicationClaimTypes.ProfilePictureDataUrl, user.ProfilePictureDataUrl)
});
}
var appuser = await _userManager.FindByIdAsync(user.Id);
var roles = await _userManager.GetRolesAsync(appuser);
var appuser = await UserManager.FindByIdAsync(user.Id);
var roles = await UserManager.GetRolesAsync(appuser);
if (roles != null && roles.Count > 0)
{
var rolesStr = string.Join(",", roles);
Expand Down