34.4 | 쿠키 인증 미들웨어 구성

     

    쿠키 인증을 사용하려면 Startup.cs 파일의 Configure() 메서드에 쿠키 인증 관련 미들웨어인 다음 코드 블록이 삽입되어야 한다.

    ▼  Startup.cs 파일의 Configure( ) 메서드의 코드 일부

    using Microsoft.AspNetCore.Http;
    
    // 쿠키 인증 사용
    app.UseCookieAuthentication(new CookieAuthenticationOptions()
    {
      AuthenticationScheme = "Cookies",
      LoginPath = new PathString("/Home/Login/"),
      AccessDeniedPath = new PathString("/Home/Forbidden/"),
      AutomaticAuthenticate = true,
      AutomaticChallenge = true
    });
    

     

    AuthenticationScheme: "Cookies" 값이 기본이고 원하는 다른 이름을 사용해도 된다. 인증을 여러 개 사용하고자 할 때는 이 값을 다르게 줄 수 있다.

    LoginPath: 인증되지 않았을 때 여기에 지정된 경로로 이동한다.

    AccessDeniedPath: 인증(Authentication)은 되었지만, 적절한 권한(Authorization)이 없을 경우 여기에 지정된 경로로 이동한다.

    AutomaticAuthenticate: 모든 요청에 대해 인증되었는지 확인하도록 설정한다.

    AutomaticChallenge: 인증이 실패했을 경우 LoginPath 또는 AccessDeniedPath에 지정된 경로로 이동하도록 설정한다.

    신간 소식 구독하기
    뉴스레터에 가입하시고 이메일로 신간 소식을 받아 보세요.