Как удалить стандартные конечные точки ASP.NET Core Identity? - PullRequest
0 голосов
/ 30 ноября 2018

Допустим, я бы хотел написать свои собственные конечные точки входа в систему, выхода из системы и их представления

Но по некоторым причинам я изо всех сил стараюсь удалить существующие конечные точки

Всякий раз, когда я удаляю вещикоторые, вероятно, связаны с этими конечными точками, затем они воссоздают сами себя и возвращают свои представления по умолчанию.

По сути, я бы хотел удалить как можно больше конечных точек / представлений по умолчанию тех, которые сгенерированы из ASP.NET Core Identity * 1007.*

Есть идеи, как мне этого добиться?

        "Templates/Identity/Pages/Account/Account.AccessDenied.cs.cshtml",
        "Templates/Identity/Pages/Account/Account.AccessDenied.cshtml",
        "Templates/Identity/Pages/Account/Account.ConfirmEmail.cs.cshtml",
        "Templates/Identity/Pages/Account/Account.ConfirmEmail.cshtml",
        "Templates/Identity/Pages/Account/Account.ExternalLogin.cs.cshtml",
        "Templates/Identity/Pages/Account/Account.ExternalLogin.cshtml",
        "Templates/Identity/Pages/Account/Account.ForgotPassword.cs.cshtml",
        "Templates/Identity/Pages/Account/Account.ForgotPassword.cshtml",
        "Templates/Identity/Pages/Account/Account.ForgotPasswordConfirmation.cs.cshtml",
        "Templates/Identity/Pages/Account/Account.ForgotPasswordConfirmation.cshtml",
        "Templates/Identity/Pages/Account/Account.Lockout.cs.cshtml",
        "Templates/Identity/Pages/Account/Account.Lockout.cshtml",
        "Templates/Identity/Pages/Account/Account.Login.cs.cshtml",
        "Templates/Identity/Pages/Account/Account.Login.cshtml",
        "Templates/Identity/Pages/Account/Account.LoginWith2fa.cs.cshtml",
        "Templates/Identity/Pages/Account/Account.LoginWith2fa.cshtml",
        "Templates/Identity/Pages/Account/Account.LoginWithRecoveryCode.cs.cshtml",
        "Templates/Identity/Pages/Account/Account.LoginWithRecoveryCode.cshtml",
        "Templates/Identity/Pages/Account/Account.Logout.cs.cshtml",
        "Templates/Identity/Pages/Account/Account.Logout.cshtml",
        "Templates/Identity/Pages/Account/Account.Register.cs.cshtml",
        "Templates/Identity/Pages/Account/Account.Register.cshtml",
        "Templates/Identity/Pages/Account/Account.ResetPassword.cs.cshtml",
        "Templates/Identity/Pages/Account/Account.ResetPassword.cshtml",
        "Templates/Identity/Pages/Account/Account.ResetPasswordConfirmation.cs.cshtml",
        "Templates/Identity/Pages/Account/Account.ResetPasswordConfirmation.cshtml",
        "Templates/Identity/Pages/Account/Account._ViewImports.cshtml",
        "Templates/Identity/Pages/Account/Manage/Account.Manage.ChangePassword.cs.cshtml",
        "Templates/Identity/Pages/Account/Manage/Account.Manage.ChangePassword.cshtml",
        "Templates/Identity/Pages/Account/Manage/Account.Manage.DeletePersonalData.cs.cshtml",
        "Templates/Identity/Pages/Account/Manage/Account.Manage.DeletePersonalData.cshtml",
        "Templates/Identity/Pages/Account/Manage/Account.Manage.Disable2fa.cs.cshtml",
        "Templates/Identity/Pages/Account/Manage/Account.Manage.Disable2fa.cshtml",
        "Templates/Identity/Pages/Account/Manage/Account.Manage.DownloadPersonalData.cs.cshtml",
        "Templates/Identity/Pages/Account/Manage/Account.Manage.DownloadPersonalData.cshtml",
        "Templates/Identity/Pages/Account/Manage/Account.Manage.EnableAuthenticator.cs.cshtml",
        "Templates/Identity/Pages/Account/Manage/Account.Manage.EnableAuthenticator.cshtml",
        "Templates/Identity/Pages/Account/Manage/Account.Manage.ExternalLogins.cs.cshtml",
        "Templates/Identity/Pages/Account/Manage/Account.Manage.ExternalLogins.cshtml",
        "Templates/Identity/Pages/Account/Manage/Account.Manage.GenerateRecoveryCodes.cs.cshtml",
        "Templates/Identity/Pages/Account/Manage/Account.Manage.GenerateRecoveryCodes.cshtml",
        "Templates/Identity/Pages/Account/Manage/Account.Manage.Index.cs.cshtml",
        "Templates/Identity/Pages/Account/Manage/Account.Manage.Index.cshtml",
        "Templates/Identity/Pages/Account/Manage/Account.Manage.ManageNavPages.cshtml",
        "Templates/Identity/Pages/Account/Manage/Account.Manage.PersonalData.cs.cshtml",
        "Templates/Identity/Pages/Account/Manage/Account.Manage.PersonalData.cshtml",
        "Templates/Identity/Pages/Account/Manage/Account.Manage.ResetAuthenticator.cs.cshtml",
        "Templates/Identity/Pages/Account/Manage/Account.Manage.ResetAuthenticator.cshtml",
        "Templates/Identity/Pages/Account/Manage/Account.Manage.SetPassword.cs.cshtml",
        "Templates/Identity/Pages/Account/Manage/Account.Manage.SetPassword.cshtml",
        "Templates/Identity/Pages/Account/Manage/Account.Manage.ShowRecoveryCodes.cs.cshtml",
        "Templates/Identity/Pages/Account/Manage/Account.Manage.ShowRecoveryCodes.cshtml",
        "Templates/Identity/Pages/Account/Manage/Account.Manage.TwoFactorAuthentication.cs.cshtml",
        "Templates/Identity/Pages/Account/Manage/Account.Manage.TwoFactorAuthentication.cshtml",
        "Templates/Identity/Pages/Account/Manage/Account.Manage._Layout.cshtml",
        "Templates/Identity/Pages/Account/Manage/Account.Manage._ManageNav.cshtml",
        "Templates/Identity/Pages/Account/Manage/Account.Manage._StatusMessage.cshtml",
        "Templates/Identity/Pages/Account/Manage/Account.Manage._ViewImports.cshtml",
        (...)

Ответы [ 2 ]

0 голосов
/ 10 декабря 2018

Я проверил исходный код на Github в ASPNET и немного его отредактировал

https://github.com/aspnet/Identity/blob/c7276ce2f76312ddd7fccad6e399da96b9f6fae1/src/UI/IdentityServiceCollectionUIExtensions.cs#L47

public static IdentityBuilder AddDefaultIdentity<TUser>(this IServiceCollection services, Action<IdentityOptions> configureOptions) where TUser : class
{
    services.AddAuthentication(o =>
    {
        o.DefaultScheme = IdentityConstants.ApplicationScheme;
        o.DefaultSignInScheme = IdentityConstants.ExternalScheme;
    })
    .AddIdentityCookies(o => { });

    return services.AddIdentityCore<TUser>(o =>
    {
        o.Stores.MaxLengthForKeys = 128;
        configureOptions?.Invoke(o);
    })
    .AddDefaultUI() // It'll be removed
    .AddDefaultTokenProviders();
}

Вот код:

Метод расширения:

public static class IServiceCollectionExtensions
{
    public static IdentityBuilder AddCustomDefaultIdentity<TUser>(this IServiceCollection services, Action<IdentityOptions> configureOptions) where TUser : class
    {
        services.AddAuthentication(o =>
        {
            o.DefaultScheme = IdentityConstants.ApplicationScheme;
            o.DefaultSignInScheme = IdentityConstants.ExternalScheme;
        })
        .AddIdentityCookies(o => { });

        return services.AddIdentityCore<TUser>(o =>
        {
            o.Stores.MaxLengthForKeys = 128;
            configureOptions?.Invoke(o);
        })
        .AddDefaultTokenProviders();
    }
}

Startup.cs

services.AddCustomDefaultIdentity<User>
(
    o => { /* options e.g */ o.Password.RequireDigit = true;}
)
.AddSignInManager()
.AddEntityFrameworkStores<Context>();

services.ConfigureApplicationCookie(options =>
{
    options.AccessDeniedPath = "some_value";
    options.Cookie.Name = "some_value";
    options.Cookie.HttpOnly = some_value;
    options.ExpireTimeSpan = TimeSpan.FromMinutes(some_value);
    options.LoginPath = "some_value";
    options.LogoutPath = "some_value";
    options.ReturnUrlParameter = CookieAuthenticationDefaults.some_value;
    options.SlidingExpiration = some_value;
});
0 голосов
/ 30 ноября 2018

Вы не можете использовать AddDefaultIdentity, так как внутренне это вызывает AddDefaultUI, который содержит "конечные точки" страниц бритвы, которые вам не нужны.Вам нужно будет использовать AddIdentity<TUser, TRole> или AddIdentityCore<TUser>.

...