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

User and Role ID should not have to be the same type #122

Open
Lukejkw opened this issue Mar 18, 2022 · 1 comment
Open

User and Role ID should not have to be the same type #122

Lukejkw opened this issue Mar 18, 2022 · 1 comment
Assignees

Comments

@Lukejkw
Copy link

Lukejkw commented Mar 18, 2022

Is your feature request related to a problem? Please describe.
We use value objects for the key IDs of our user and role objects. However, registration requires these values to be the same type when making a call to AddIdentityMongoDbProvider

Describe the solution you'd like

It would be nice to be able to define the key types for the user and role separately rather than forcing them to be the same type.

 builder.Services
            .AddAuthorization()
            .AddIdentityMongoDbProvider<ApplicationUser, ApplicationRole, UserId>( // <--- It would be nice to be able to specify the ID types for user and role separately
                identityOptions => { identityOptions.SignIn.RequireConfirmedAccount = false; },
                mongoIdentityOptions =>
                {
                    mongoIdentityOptions.ConnectionString = builder.Configuration.GetConnectionString("MongoDB");
                })
            .AddDefaultTokenProviders();

Describe alternatives you've considered

The alternative would be use the underlying type such as a Guid. However, you lose the strong typing of the value object. I'm also not sure registering a Guid serialiser for a nice readable guid currently works.

Example:

builder.Services
            .AddAuthorization()
            .AddIdentityMongoDbProvider<ApplicationUser, ApplicationRole, Guid>(
                identityOptions => { identityOptions.SignIn.RequireConfirmedAccount = false; },
                mongoIdentityOptions =>
                {
                    mongoIdentityOptions.ConnectionString = builder.Configuration.GetConnectionString("MongoDB");
                })
            .AddDefaultTokenProviders();
            
BsonSerializer.RegisterSerializer(new GuidSerializer(BsonType.String));
@vova3211 vova3211 self-assigned this Aug 26, 2024
@vova3211
Copy link
Collaborator

hi @Lukejkw ,
not sure if it's still relevant, but I'll take a look.

usually you want consistent key type across application, but if someone requires it (and it's possible to implement) I believe we shoud support it.

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

2 participants