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

Very complex configuration #430

Open
fatalistt opened this issue Dec 3, 2019 · 11 comments
Open

Very complex configuration #430

fatalistt opened this issue Dec 3, 2019 · 11 comments

Comments

@fatalistt
Copy link

fatalistt commented Dec 3, 2019

In Startup.ConfigureServices of Admin and AdminApi projects there are lots of Type parameters (Admin, for example).
It's very difficult to understand, which parameter user should to change if he want to change something.
I suppose to create a builder to split this method. It'll look something like this:

services.AddAdminAspNetIdentityServices(); // With default values like string keys, DbContexts, etc.
services.AddAdminAspNetIdentityServices(admin => {
    admin.ConfigureIdentity(identity => {
        identity.ConfigureKeys(keys => {
            keys.UseUserKey<string>();
            ...
        })
        .ConfigureEntities(entities => {
            entities.UseUser<IdentityUser<string>>();
            ...
        });
    }
    ...
});

In configuration we start from default values, so user can skip some blocks like ConfigureKeys.
I start to making this, but I have some question for now (may be I'll add some more later):
In Skoruba.IdentityServer4.Admin.EntityFramework.Identity.Repositories.IdentityRepository you have TUserKey, TRoleKey, and TKey parameters (src).
TUserKey and TRoleKey are never used except these 2 methods: ConvertUserKeyFromString and ConvertRoleKeyFromString
All other parameters are depend from TKey (TUser : IdentityUser<TKey>, for example).
Later you use UserManager<IdentityUser<TKey>>.Users.AnyAsync(x => x.Id.Equals(_instance of TUserKey_)); here.
If TKey and TUserKey will be a different types, this code will fall, isn't it?

@skoruba
Copy link
Owner

skoruba commented Dec 3, 2019

You are right, this configuration is maybe too complex.
Yes, TKey and TUserKey must be same type. I like your approach, we can rewrite this, if you can send some PR, it would be great.

@skoruba skoruba added the task Task label Dec 3, 2019
@fatalistt
Copy link
Author

fatalistt commented Dec 3, 2019

Yes, I will make a PR later when i finished it.
If TKey and TUserKey (TRoleKey) must be the same type, why do we need TUserKey (TRoleKey) ever?

@skoruba
Copy link
Owner

skoruba commented Dec 3, 2019

This is great question, I would prefer separate keys for User and Role, maybe we can remove TKey at all and keep only TUserKey and TRoleKey. What do you think?

@fatalistt
Copy link
Author

Yes, it's better to remove TKey, but what about the keys in TUserClaim, TUserRole, TUserLogin, TRoleClaim and TUserToken? Which keys they should to use? I didn't work with ASP.Net Identity so deep before, so I know nothing about these keys.

@skoruba
Copy link
Owner

skoruba commented Dec 3, 2019

These objects are connected with TUserKey and TRoleKey. For example: TUserClaim is object which uses TUserKey. You are not able to specify primary key for TUserClaim but you can specify primary key for User which is used in TUserClaim. Does it make sense for you?

@fatalistt
Copy link
Author

Yes, I think, it does. But after looking to sources of Identity there are some questions.
IdentityUserClaim<TUserKey>, IdentityUserLogin<TUserKey>, IdentityRoleClaim<TRoleKey> and IdentityUserToken<TUserKey> are contains only one of [TUserKey UserId, TRoleKey RoleId].
But IdentityUserClaim<TKey> contains both TKey RoleId and TKey UserId, which means that TUserKey and TRoleKey are the same type TKey, so we're not able to split TKey to two different types. Am i right?

@skoruba
Copy link
Owner

skoruba commented Dec 3, 2019

Can you send me which part do you mean?

@fatalistt
Copy link
Author

fatalistt commented Dec 4, 2019

Yes, of course.
IdentityUserRole from AspNetCore.
Constraint for TUserRole in your code.

@skoruba
Copy link
Owner

skoruba commented Dec 4, 2019

You are right, thanks for this point. We should use only one key - TKey, becuase of this limitation.

@b0
Copy link
Contributor

b0 commented Feb 16, 2020

Hi @skoruba and @fatalistt,

I was looking at this issue and associated PR and me too find that configuration is a bit complex and definitively there is TRoleKey and TUserKey type params too much.

I find PR maybe a bit too big so maybe it's possible to split it in two, one for TRoleKey and TUserKey removal and another for simplified configuration?

What do you think?

Thank you

@skoruba
Copy link
Owner

skoruba commented Feb 16, 2020

Hi @b0 I definitely agree with you, I am happy for this PR, but it is too complex - splitting would be perfect.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants