1

私はAzureで3つのWebアプリケーションを使用しています。サブドメインのGoogle認証とCookie認証付きAsp.Netコア2

  • のwebapp1はwww.mydomain.com
  • webapp2をがWebapp3があるadmin.mydomain.com
  • あるuser.mydomain.com

私は上のログにWebApp1です他のすべてのサブドメインにログオンしたい

ソーシャルプロバイダを使用してユーザーを認証し、認証にasp.net IDを使用したいと考えています。

ここSO質問にドキュメント&を読んだ後、私はクッキーはのwebapp1に正常に動作しているが、添付のドメインがo.Cookieで定義されたものとしてではない、私のStartup.cs

public void ConfigureServices(IServiceCollection services) 
{ 
    /* 
    * Some code 
    */ 

    // Creating a blob storage account to share keys for all applications 
    var storageAccount = CloudStorageAccount.Parse(configuration.GetConnectionString("IdentityStr")); 
    CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient(); 
    CloudBlobContainer container = blobClient.GetContainerReference("identity"); 
    AsyncContext.Run(() => container.CreateIfNotExistsAsync()); 

    services.AddDataProtection() 
      .SetApplicationName("MYAPP") 
      .PersistKeysToAzureBlobStorage(container, "keys.xml"); 

    /* 
    * BEGIN DISGUSTING: I recreate the data protection provider here 
    * because I need the instance of it below for the Cookie options 
    */ 
    var serviceCollection = new ServiceCollection(); 
    serviceCollection.AddDataProtection() 
      .SetApplicationName("MYAPP") 
      .PersistKeysToAzureBlobStorage(container, "keys.xml"); 
    var service2 = serviceCollection.BuildServiceProvider(); 
    var dataProtector = service2.GetRequiredService<IDataProtectionProvider>(); 
    /* 
    * END DISGUSTING 
    */ 

    services.AddDbContext<AuthDbContext>(options => 
      options.UseSqlServer(connectionString)); 

    services.AddIdentity<AuthUser, AuthRole>() 
      .AddEntityFrameworkStores<AuthDbContext>() 
      .AddDefaultTokenProviders(); 

    services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme) 
      .AddCookie(o => 
      { 
       o.LoginPath = "/account/login"; 
       o.LogoutPath = "/account/logout"; 
       o.Cookie.Domain = "mydomain.com"; 
       o.DataProtectionProvider = dataProtector; 
       o.TicketDataFormat = new TicketDataFormat(dataProtector.CreateProtector("Microsoft.AspNetCore.Authentication.Cookies.CookieAuthenticationMiddleware", "Cookies", "v2")); 
      }) 
      .AddGoogle(o => 
      { 
       o.ClientId = configuration["Authentication:Google:ClientId"]; 
       o.ClientSecret = configuration["Authentication:Google:ClientSecret"]; 
      }); 

    /* 
    * Some code 
    */ 
} 

public void Configure(IApplicationBuilder app, IHostingEnvironment env) 
{ 
    /* 
    * Some code 
    */ 

    app.UseAuthentication(); 

    /* 
    * Some code 
    */ 
} 

に持っているものです。 enter image description here 012:ドメインが、www.mydomain.omここ

は、Chromeのクッキー cookies

そして、フィドラーズ・ビューの図です。私はおそらく何かを見逃しました...

答えて

1

IDクッキーにはドメインセットがありません。あなたは

を作成している新しいものがそうConfigureApplicationCookie

services.AddIdentity<AuthUser, AuthRole>() 
     .AddEntityFrameworkStores<AuthDbContext>() 
     .AddDefaultTokenProviders(); 

services.AddAuthentication() 
     .AddGoogle(o => 
     { 
      // Google options. 
     }); 

services.ConfigureApplicationCookie(options => 
{ 
    // Cookie settings 
}); 
を使用してみてください、ではないアイデンティティはすでにそれを追加しますので、あなたは、クッキーをもう一度追加する必要はありません、あなたはそのインスタンスを設定する必要があります