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

MissingFieldException for 'MongoDbContext' in AspNetCore.Identity.Mongo during Password Reset #127

Open
lincolnqjunior opened this issue May 10, 2024 · 0 comments

Comments

@lincolnqjunior
Copy link

Describe the Bug:
When attempting to reset a password using userManager.ResetPasswordAsync in a .NET application configured with AspNetCore.Identity.Mongo, an exception is raised indicating a missing field error: Field not found: 'MongoDbGenericRepository.ReadOnlyMongoRepository1.MongoDbContext'.`

To Reproduce:
Steps to reproduce the behavior:

  1. Configure the application's identity services in Program.cs with the following settings:
var mongoIdentityConfig = new MongoDbIdentityConfiguration
{
    MongoDbSettings = new MongoDbSettings() { ConnectionString = "your_connection_string", DatabaseName = "auth-db" },
    IdentityOptionsAction = options =>
    {
        options.Password.RequiredLength = 8;
        // Other options...
    }
};

services
    .ConfigureMongoDbIdentity<ApplicationUser, ApplicationRole, Guid>(mongoIdentityConfig)
    .AddMongoDbStores<ApplicationUser, ApplicationRole, Guid>("your_connection_string", "auth-db")
    .AddDefaultTokenProviders();
  1. Execute the following test code:
private async Task TestResetPassword()
{
    var user = await _userManager.FindByEmailAsync("[email protected]");
    var token = await _userManager.GeneratePasswordResetTokenAsync(user);
    var result = await _userManager.ResetPasswordAsync(user, token, "NewPassword123!");
    if (result.Succeeded)
    {
        Console.WriteLine("Password reset succeeded.");
    }
    else
    {
        result.Errors.ToList().ForEach(error => Console.WriteLine($"Error: {error.Code} - {error.Description}"));
    }
}

Expected behavior
The password should be successfully reset without any exceptions.

Screenshots
image
image
image

Environment:

  • Target framework: .NET 8.0
  • MongoDB Driver Version: [2.25.0]
  • AspNetCore.Identity.Mongo Version: [3.1.2]
  • Operating System: [specify OS and version]
  • Dependencies:
    image
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant