Search code examples
c#identityserver4

How can i save cookies in deployed app using identity server?


I'm using Identity server 4 OAuth to protect my app. In Development everything works ok. So i deployed my app in minikube and connected using localhost and everything still works. But when i connect from another PC using ip cookies are not saved and i'm unable to log in. Are there any options that i need to handle in order to start saving cookies?

 public void ConfigureServices(IServiceCollection services)
    {
        services.AddControllersWithViews()
            .AddRazorRuntimeCompilation();

        services.AddIdentityServerConfiguration(_config);

        var migrationsAssembly = typeof(Startup).GetTypeInfo().Assembly.GetName().Name;

        services.AddIdentityServer()
            .AddAspNetIdentity<IdentityUser>()
            .AddConfigurationStore(options =>
            {
                options.ConfigureDbContext = b =>
                    b.UseNpgsql(_config.GetConnectionString(nameof(ApplicationDbContext)),
                        sql => sql.MigrationsAssembly(migrationsAssembly));
            })
            .AddOperationalStore(options =>
            {
                options.ConfigureDbContext = b =>
                    b.UseNpgsql(_config.GetConnectionString(nameof(ApplicationDbContext)),
                        sql => sql.MigrationsAssembly(migrationsAssembly));
            })
            .AddDeveloperSigningCredential();

        services.ConfigureApplicationCookie(config =>
        {
            config.Cookie.Name = "IdentityServer.Cookies";
            config.Cookie.HttpOnly = false;
        });
    }

Solution

  • The problem was with the certificate. As soon as i started using a self-signed certificate and https:// everything works ok https://learn.microsoft.com/en-us/aspnet/core/security/docker-https?view=aspnetcore-3.1