Asp. net Core 3.1 Backend не получает идентификационные данные из cookie - PullRequest
0 голосов
/ 15 января 2020

У меня есть vue. js интерфейс и asp. net ядро ​​3.1. Backend использует SignInManager и Identity. Я пытаюсь использовать аутентификацию cook ie. Api-запросы работают от Postman (!!), применяются роли, все, но не из vue приложения (httpContext.User.Identity.IsAuthenticated - false). Идентичность пуста. Cook ie присутствует в HttpContext

        public void ConfigureServices(IServiceCollection services)
    {
        services.AddDbContext<MyDBContext>(options => options.UseSqlServer(Configuration["ConnectionStrings:Default"]));
        services.AddCors();
        services.AddControllers()
        services.AddIdentity<AppUser, IdentityRole>(
            opts =>
            {
                opts.SignIn.RequireConfirmedEmail = true;
            }
            )
            .AddSignInManager<SignInManager<AppUser>>()
            .AddEntityFrameworkStores<MyDBContext>()
            .AddDefaultTokenProviders();

        services.ConfigureApplicationCookie(options =>
        {
            // Cookie settings
            options.Cookie.HttpOnly = true;
            options.ExpireTimeSpan = TimeSpan.FromMinutes(60);
            options.Cookie.SameSite = SameSiteMode.None;
            options.SlidingExpiration = true;
        });

       //some DI
       ...
       //
       }

немного больше Startup.cs

public void Configure(IApplicationBuilder app, IWebHostEnvironment env, UserManager<AppUser> userManager)
    {
        app.UseRouting();
        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
        }

        app.UseCors(x => x
            .AllowAnyOrigin()
            .AllowAnyMethod()
            .AllowAnyHeader());
        app.UseHttpsRedirection();


        app.UseAuthentication();
        app.UseAuthorization();
        app.UseEndpoints(endpoints =>
        {
            endpoints.MapControllers();
        });

    }

Я пытался прокси-запросы к API в приложении vue. Не помогло

module.exports = {
devServer: {
   proxy: {
     '^/api': {
       target: 'https://localhost:44376',
       ws: true,
       changeOrigin: true
     }
   }
  }
}

Что может быть не так?

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