powered by simpleCommunicator - 2.0.51     © 2025 Programmizd 02
Форумы / ASP.NET [игнор отключен] [закрыт для гостей] / No authentication handler is configured to authenticate for the scheme (core 2)
1 сообщений из 1, страница 1 из 1
No authentication handler is configured to authenticate for the scheme (core 2)
    #39556961
handmadeFromRu
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
стандартная авторизация через клаймс работает на ура. но мне надо для совместимости старого сделать авторизацию по определенным токенам, не jwt.

так регистрирую
Код: c#
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
 public IServiceProvider ConfigureServices(IServiceCollection services, IConfiguration configuration){
.....
 services.AddAuthentication(options =>
            {
                options.DefaultScheme = AuthenticationDefaults.TokenScheme;
            }).AddToken(services);
.....
}

public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
....
app.UseAuthentication();
...
}


Код: c#
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
public static AuthenticationBuilder AddToken(this AuthenticationBuilder builder, IServiceCollection services)
        {
            return builder.AddScheme<TokenAuthenticationOptions, TokenAuthenticationHandler>(
                AuthenticationDefaults.TokenAuthenticationScheme, options =>
                {
                    var provider = services.BuildServiceProvider();
                    options.Logger = provider.GetService<ILogger>();
                    options.CustomerService= provider.GetService<ICustomerService>();
                    options.AuthenticationProcess = provider.GetService<IAuthenticationProcess>();
                }
                );
        }


опция с прокинутыми сервисами
Код: c#
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
public class TokenAuthenticationOptions: AuthenticationSchemeOptions
    {        

        public IAuthenticationProcess AuthenticationProcess { get; set; }

        public ICustomerService CustomerService{ get; set; }

        public ILogger Logger { get; set; }

        public override void Validate()
        {
            if (LicKeyAuthenticationProcess == null)
                throw new NullReferenceException($"{nameof(AuthenticationProcess)} is null");

            if (ServiceUserRepository == null)
                throw new NullReferenceException($"{nameof(CustomerService)} is null");

            if (Logger == null)
                throw new NullReferenceException($"{nameof(Logger)} is null");
        }
    }


сам хедлер
Код: c#
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
 public class TokenAuthenticationHandler : AuthenticationHandler<TokenAuthenticationOptions>
    {
        protected TokenAuthenticationHandler (IOptionsMonitor<TokenAuthenticationOptions> options, ILoggerFactory logger, UrlEncoder encoder, ISystemClock clock) : base(options, logger, encoder, clock)
        {
        }

        protected override Task<AuthenticateResult> HandleAuthenticateAsync()
        {
              тут код логики
        }
    }


схему ставлю руками на контролере
Код: c#
1.
2.
3.
 [Authorize(AuthenticationSchemes = AuthenticationDefaults.TokenAuthenticationScheme)]
    public class SomeController : Controller{
}


в итоге получаю No authentication handler is configured to authenticate for the scheme.
Что я пропустил в регистрации?
...
Рейтинг: 0 / 0
1 сообщений из 1, страница 1 из 1
Форумы / ASP.NET [игнор отключен] [закрыт для гостей] / No authentication handler is configured to authenticate for the scheme (core 2)
Целевая тема:
Создать новую тему:
Автор:
Закрыть
Цитировать
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]