AspNetCore - 使用Google身份验证时更改Cookie名称

Cie*_*iel 5 asp.net-identity asp.net-core

在ASP.NET 5,MVC 6中,我能够在选项中更改外部身份验证cookie的名称 - 但这似乎是从AspNetCore.Identity RC2库中的新提供程序中删除的.

我有这个设置;

class Startup {
   ...
   public void ConfigureServices(IServiceCollection services){
      services.AddIdentity<Member, Role> ... // identity wired up
   }

   public void Configure(IApplicationBuilder app, ILoggerFactory logger) {
      // .. other wiring
    app
        .UseIdentity()
        .UseGoogleAuthentication
        (new GoogleOptions {
            ClientId = Constants.Google.Client,
            ClientSecret = Constants.Google.Secret,
            Scope = {"email", "profile"}
        });

    app.UseMvc(routes => {
        routes.MapRoute(
            name: "default",
            template: "{controller=Home}/{action=Index}/{id?}");
         });
    }
}
Run Code Online (Sandbox Code Playgroud)

曾经有一个AuthenticationType我可以设置为a 的属性,string它将控制cookie名称; 但那已经消失了.

我读其他职位,说去尝试SignInScheme和AuthenticationScheme-和我做,但是这将开始给我说,有一个错误No Provider to Handle this Scheme.

有什么我可以做的吗?

Kév*_*let 6

以下是如何替换用于外部cookie的默认名称.

services.AddIdentity<Member, Role>(options =>
{
    options.Cookies.ExternalCookie.CookieName = "name";
});
Run Code Online (Sandbox Code Playgroud)


avv*_*sis 5

在VS2017中对我有用

在Startup.cs ConfigureServices()中:

services.ConfigureApplicationCookie(options => {
  options.Cookie.Name = "NewCookieName";
});
Run Code Online (Sandbox Code Playgroud)


GSe*_*rjo 5

ASP.NET 核心 2.2

services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
    .AddCookie(options =>
    {
        options.Cookie.Name = "my_cookie";
    });
Run Code Online (Sandbox Code Playgroud)