0

현재 ASP.NET Core Identity를 사용 중입니다. 세션 길이를 연장하는 설정을 알 수는 없지만 로그 아웃 상태가 계속됩니다. 슬라이딩 만료가 ~ 20 분이라고 가정하지만 설정을 찾을 수 없습니다. 참고로 Google을 외부 OAuth로 사용하고 있습니다.ASP.NET Core Identity 만료 (Google OAuth)

 services.AddIdentity<ApplicationUser, IdentityRole>(o => 
      { 
       o.Password.RequireDigit = false; 
       o.Password.RequireLowercase = false; 
       o.Password.RequireUppercase = false; 
       o.Password.RequireNonAlphanumeric = false; 
       o.Password.RequiredLength = 6; 
       o.SecurityStampValidationInterval = TimeSpan.FromHours(8); 
       o.Cookies.ExternalCookie.ExpireTimeSpan = TimeSpan.FromHours(8); 
       o.Cookies.ApplicationCookie.ExpireTimeSpan = TimeSpan.FromHours(8); 
      }) 
      .AddEntityFrameworkStores<ApplicationDbContext>() 
      .AddDefaultTokenProviders(); 


     app.UseIdentityServer(); 

     app.UseIdentityServerAuthentication(new IdentityServerAuthenticationOptions 
     { 
      Authority = $"http://localhost:55504/", 
      RequireHttpsMetadata = false, 
      AllowedScopes = 
      { 
       IdentityServerConstants.StandardScopes.OpenId, 
       IdentityServerConstants.StandardScopes.Profile, 
       IdentityServerConstants.StandardScopes.Email, 
       "name", 
       "given_name", 
       "family_name", 
       "role" 
      } 
     }); 

     var googleOptions = serviceProvider.GetRequiredService<GoogleOptions>(); 
     app.UseGoogleAuthentication(new GoogleOptions 
     { 
      AuthenticationScheme = "Google", 
      SignInScheme = "Identity.External", 
      ClientId = googleOptions.ClientId, 
      ClientSecret = googleOptions.ClientSecret 
     }); 
+0

가능한 중복 [쿠키 코어가 ASP.NET 코어에서 너무 빨리 만료 됨] (https://stackoverflow.com/questions/45595615/c) ookie-authentication-expiring-too-soon-asp-net-core) – SteelToe

+0

응용 프로그램을 호스팅하는 곳과 방법은 무엇입니까? IIS? Azure App 서비스? 그런 다음 쿠키에 대한 암호화 키가 응용 프로그램을 다시 시작할 때까지 데이터 보호가 가능해야합니다. [내 대답은 여기에 있습니다.] (https://stackoverflow.com/a/47559544/455493) – Tseng

답변

0

이 질문에 \ 대답은 당신이 당신의 구성처럼 뭔가를 할 것 4.

신원 서버에 특정 :

app.UseGoogleAuthentication(new GoogleOptions 
{ 
    SignInScheme = "Identity.External", // this is the name of the cookie middleware registered by UseIdentity() 
    ClientId = Configuration["ExternalAuthentication:Google:ClientId"], 
    ClientSecret = Configuration["ExternalAuthentication:Google:ClientSecret"] 
}); 

app.UseIdentityServerAuthentication(new IdentityServerAuthenticationOptions 
{ 
    Authority = $"http://localhost:55504/", 
    RequireHttpsMetadata = false, 
    AllowedScopes = 
    { 
     IdentityServerConstants.StandardScopes.OpenId, 
     IdentityServerConstants.StandardScopes.Profile, 
     IdentityServerConstants.StandardScopes.Email, 
     "name", 
     "given_name", 
     "family_name", 
     "role" 
    } 
     // CookieLifetime default is 10 Hours 
     Authentication.CookieLifetime = TimeSpan.FromHours(24); 

     // Default CookieSlidingExpiration = false; 
     Authentication.CookieSlidingExpiration = true; 
}); 

하고 ConfigureServices에를

// Identity 
    // https://docs.microsoft.com/en-us/aspnet/core/security/authentication/identity 
    // http://docs.identityserver.io/en/release/quickstarts/6_aspnet_identity.html 
    services.AddIdentity<ApplicationUser, IdentityRole>(o => { 
      // configure identity options 
      o.Password.RequireDigit = false; 
      o.Password.RequireLowercase = false; 
      o.Password.RequireUppercase = false; 
      o.Password.RequireNonAlphanumeric = false; 
      o.Password.RequiredLength = 6; 
     }) 
      .AddEntityFrameworkStores<AuthDbContext>() 
      .AddDefaultTokenProviders(); 
+0

응용 프로그램이 재활용되고 암호화 키가 손실되고 다음에 새로운 암호화 키가 생성되면 그에게 도움이되지 않습니다. – Tseng

+0

I 커프스 답을 인정했다. 하지만 MS Identity 및 IdentityServer 4를 사용하여 Azure에서 호스팅되는 Google OAuth를 사용하여 서버 재시작 사이에서 현재 작업중인 코드로 내 대답을 업데이트 할 것입니다. "Idenity"라는 이름은 코드에서 2 개의 별도 패키지 중 일부입니다. – ttugates

+0

IS4의 토큰 워크 플로우를 통해 문제가 발생하지 않으며, OOB AccountController 및 CookieAuthentication을 통해 문제가 발생합니다. IS4를 비활성화하고 오류가 여전히 있는지 확인합니다. –