и иметь возможность получать в нем имя пользователя
как это сделать?
я использую внешний OIDC
так что в API у меня есть только
Код: Выделить всё
builder.Services
.AddAuthentication("Bearer")
.AddJwtBearer("Bearer", options =>
{
options.Authority = "https://xxxx/auth/realms/dev";
options.TokenValidationParameters.ValidateAudience = false;
});
Код: Выделить всё
builder.Services.AddScoped();
Код: Выделить всё
public DbLoggerProvider(IOptions options, AuthenticationStateProvider asp)
Код: Выделить всё
System.AggregateException
Message=Some services are not able to be constructed
Source=Microsoft.Extensions.DependencyInjection
StackTrace:
at
Microsoft.Extensions.DependencyInjection.ServiceProvider. .ctor(ICollection`1 serviceDescriptors, ServiceProviderOptions options)
at
Microsoft.Extensions.DependencyInjection.ServiceCollection
ContainerBuilderExtensions.BuildServiceProvider
(IServiceCollection services, ServiceProviderOptions options)
at Microsoft.Extensions.Hosting.HostApplicationBuilder.Build()
at Microsoft.AspNetCore.Builder.WebApplicationBuilder.Build()
at Program.$(String[] args) in D:\x\Server\Program.cs:line
153
This exception was originally thrown at this call stack:
[External Code]
Inner Exception 1:
InvalidOperationException: Error while validating the service
descriptor 'ServiceType: Microsoft.Extensions.Hosting.IHostApplicationLifetime Lifetime: Singleton ImplementationType: Microsoft.Extensions.Hosting.Internal.ApplicationLifetime': Unable to resolve service for type 'Microsoft.AspNetCore.Components.Authorization.AuthenticationStateProvider' while attempting to activate 'x.Server.Core.Providers.DbLoggerProvider'.
Inner Exception 2:
InvalidOperationException: Unable to resolve service for type
'Microsoft.AspNetCore.Components.Authorization.
AuthenticationStateProvider' while attempting to activate
'x.Server.Core.Providers.DbLoggerProvider'.
Код: Выделить всё
string login = User.Claims.Where(p => p.Type == "preferred_username").First().Value;
как контроллер получает этот объект пользователя, если не из AuthenticationStateProvider ?
спасибо и привет
Подробнее здесь: https://stackoverflow.com/questions/757 ... pi-project
Мобильная версия