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

Identity: IdentityOptions should be inside an IOptionsSnapshot #55162

Open
1 task done
gumbarros opened this issue Apr 16, 2024 · 1 comment
Open
1 task done

Identity: IdentityOptions should be inside an IOptionsSnapshot #55162

gumbarros opened this issue Apr 16, 2024 · 1 comment
Labels
area-identity Includes: Identity and providers enhancement This issue represents an ask for new feature or an enhancement to an existing one
Milestone

Comments

@gumbarros
Copy link

gumbarros commented Apr 16, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

If the user changes at runtime the IdentityOptions the changes are not reflected.

Expected Behavior

Changed IdentityOptions should be reflected.

Steps To Reproduce

  1. Create a simple project dotnet new mvc --auth Individual.
  2. At Program.cs
builder.Services.AddOptions<IdentityOptions>().BindConfiguration("Identity");
  1. Create a User
  2. Change the PasswordOptions. at appsettings.json or another configuration source.
  3. Try to create another User with the changed options, they are not reflected until another restart.

Exceptions (if any)

No response

.NET Version

8.0.204

Anything else?

The cause is this constructor, it should be IOptionsSnapshot

IOptions<IdentityOptions> optionsAccessor,

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-identity Includes: Identity and providers label Apr 16, 2024
@gumbarros gumbarros changed the title [ASP.NET Core Identity] IdentityOptions should be inside an IOptionsMonitor Identity: IdentityOptions should be inside an IOptionsMonitor Apr 16, 2024
@gumbarros gumbarros changed the title Identity: IdentityOptions should be inside an IOptionsMonitor Identity: IdentityOptions should be inside an IOptionsSnapshot Apr 16, 2024
@gumbarros
Copy link
Author

Workaround if anyone needs, just inherit UserManager:

public class WebPortalUserManager<T>(
    IUserStore<T> store,
    IOptionsSnapshot<IdentityOptions> optionsAccessor,
    IPasswordHasher<T> passwordHasher,
    IEnumerable<IUserValidator<T>> userValidators,
    IEnumerable<IPasswordValidator<T>> passwordValidators,
    ILookupNormalizer keyNormalizer,
    IdentityErrorDescriber errors,
    IServiceProvider services,
    ILogger<UserManager<T>> logger)
    : UserManager<T>(store, optionsAccessor, passwordHasher, userValidators, passwordValidators, keyNormalizer, errors,
        services, logger)
    where T : class;
    

At Program.cs

builder.Services
    .AddIdentity<WebPortalIdentityUser, IdentityRole>()
    .AddEntityFrameworkStores<WebIdentityDbContext>()
    .AddErrorDescriber<IdentityPortugueseErrorDescriber>()
    .AddDefaultTokenProviders()
    .AddSignInManager<SignInManager<WebPortalIdentityUser>>() 
    .AddUserManager<WebPortalUserManager<WebPortalIdentityUser>>() //This will do the job.
    .AddUserStore<UserStore<WebPortalIdentityUser, IdentityRole, WebIdentityDbContext, string>>() 
    .AddRoleStore<RoleStore<IdentityRole, WebIdentityDbContext, string>>();

@SteveSandersonMS SteveSandersonMS added this to the Backlog milestone Apr 30, 2024
@SteveSandersonMS SteveSandersonMS added the enhancement This issue represents an ask for new feature or an enhancement to an existing one label Apr 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-identity Includes: Identity and providers enhancement This issue represents an ask for new feature or an enhancement to an existing one
Projects
None yet
Development

No branches or pull requests

2 participants