В подпретензии отсутствует идентификатор сервера mongoDb 4 с использованием SignInManager - PullRequest
0 голосов
/ 25 марта 2020

Используя SignInManager, я получаю пропущенную претензию

public virtual async Task SignInWithClaimsAsync(TUser user, AuthenticationProperties authenticationProperties, IEnumerable<Claim> additionalClaims)
        {
            var userPrincipal = await CreateUserPrincipalAsync(user);
            foreach (var claim in additionalClaims)
            {
                userPrincipal.Identities.First().AddClaim(claim);
            }
            await Context.SignInAsync(IdentityConstants.ApplicationScheme,
                userPrincipal,
                authenticationProperties ?? new AuthenticationProperties());
        }

Из вышеприведенного кода userPrincipal имеет значение null, как мы видим на снимке экрана ниже

enter image description here

Вот коллекция mon go db

enter image description here

Но в строке № 238 я могу видеть Идентичность как показано ниже

enter image description here

В классе запуска у меня есть следующий код

services.AddAuthentication(o =>
            {

                o.DefaultScheme = IdentityConstants.ApplicationScheme;
                o.DefaultSignInScheme = IdentityConstants.ExternalScheme;
            });
            services.AddIdentityServer(
                    options =>
                    {
                        options.Events.RaiseSuccessEvents = true;
                        options.Events.RaiseFailureEvents = true;
                        options.Events.RaiseErrorEvents = true;
                    }
                )
                .AddMongoRepository()
                .AddMongoDbForAspIdentity<ApplicationUser, IdentityRole>(Configuration)
                .AddClients()
                .AddIdentityApiResources()
                .AddPersistedGrants()
                .AddDeveloperSigningCredential(); 



app.UseAuthorization();
            app.UseIdentityServer();

Ошибка

sub claim is missing
   at IdentityServer4.Hosting.IdentityServerAuthenticationService.AssertRequiredClaims(ClaimsPrincipal principal)
   at IdentityServer4.Hosting.IdentityServerAuthenticationService.AugmentPrincipal(ClaimsPrincipal principal)
   at IdentityServer4.Hosting.IdentityServerAuthenticationService.SignInAsync(HttpContext context, String scheme, ClaimsPrincipal principal, AuthenticationProperties properties)
   at Microsoft.AspNetCore.Identity.SignInManager`1.SignInWithClaimsAsync(TUser user, AuthenticationProperties authenticationProperties, IEnumerable`1 additionalClaims)

enter image description here

В соответствии с документом Identity Server

Когда вы входите в систему, вы должны подать как минимум суб-заявку и заявку на имя.

return new List<TestUser>
            {
                new TestUser
                {
                    SubjectId = Guid.NewGuid().ToString(),
                    Username = "admin@local.com",
                    Password = "RockStar.1",

                    Claims = new List<Claim>
                    {
                        new Claim(JwtClaimTypes.Name, "Admin "),
                        new Claim(JwtClaimTypes.GivenName, "Admin"),
                        new Claim(JwtClaimTypes.FamilyName, "add min"),
                        new Claim(JwtClaimTypes.Email, "admin@local.com")
                    }
                }
            };

Как назначить подпретензию?

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...