1

나는 Azure에서 3 개의 웹 응용 프로그램을 보유하고 있습니다.하위 도메인에 Google 인증 및 쿠키 인증을 사용하는 Asp.Net Core 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 여기

크롬의 쿠키 cookies

그리고 피들러의 전망을 볼 수있다뭔가를 놓친 것 같습니다 ...

답변

1

ID 쿠키에 도메인 집합이 없습니다. 당신은 신원이 이미 추가하기 때문에, 쿠키를 두 번째로 추가 할 필요가 없습니다, 당신은 그래서 사용해보십시오 인스턴스가 아닌 당신이

를 만드는 새로운 하나를 구성해야 ConfigureApplicationCookie

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

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

services.ConfigureApplicationCookie(options => 
{ 
    // Cookie settings 
});