Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AspNetCore - change cookie name when using Google Authentication

In ASP.NET 5, MVC 6, I was able to change the name of the external authentication cookie in the options - but that seems to be removed from the new providers in AspNetCore.Identity RC2 libraries.

I've got this setup;

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?}");
         });
    }
}

There used to be an AuthenticationType property that I could set to a string and it would control the cookie name; But that's gone.

I read other posts that said to try SignInScheme and AuthenticationScheme - and I did, but that would start giving me an error that there was No Provider to Handle this Scheme.

Is there anything I can do for it?

like image 515
Ciel Avatar asked Apr 12 '16 02:04

Ciel


Video Answer


2 Answers

Here's how you can replace the default name used for the external cookie.

services.AddIdentity<Member, Role>(options =>
{
    options.Cookies.ExternalCookie.CookieName = "name";
});
like image 99
Kévin Chalet Avatar answered Nov 03 '22 00:11

Kévin Chalet


It's work for me in VS2017

In the Startup.cs ConfigureServices():

services.ConfigureApplicationCookie(options => {
  options.Cookie.Name = "NewCookieName";
});
like image 33
avvensis Avatar answered Nov 02 '22 23:11

avvensis