{"title":"“REMOTE_USER”를 이용해 인증하는 방법","version":"6.1","locale":"ko","docname":"howto/auth-remote-user","url":"/ko/6.1/howto/auth-remote-user/","canonical":"https://djangodocs.dev/ko/6.1/howto/auth-remote-user/","summary":"This document describes how to make use of external authentication sources in your Django applications. This type of authentication solution is typically seen on…","html":"<h1>“REMOTE_USER”를 이용해 인증하는 방법<a class=\"heading-anchor\" href=\"#how-to-authenticate-using-remote-user\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h1>\n<p>This document describes how to make use of external authentication sources in\nyour Django applications. This type of authentication solution is typically\nseen on intranet sites, with single sign-on solutions such as IIS and\nIntegrated Windows Authentication or Apache and <a class=\"reference external\" href=\"https://httpd.apache.org/docs/current/mod/mod_authnz_ldap.html\">mod_authnz_ldap</a>, <a class=\"reference external\" href=\"https://www.apereo.org/projects/cas\">CAS</a>,\n<a class=\"reference external\" href=\"https://uit.stanford.edu/service/authentication\">WebAuth</a>, <a class=\"reference external\" href=\"https://sourceforge.net/projects/mod-auth-sspi\">mod_auth_sspi</a>, etc.</p>\n<p>When the web server takes care of authentication it typically provides the\nauthenticated user as <code class=\"docutils literal notranslate\"><span class=\"pre\">REMOTE_USER</span></code>. In Django, this value is made available\nin <a class=\"reference internal\" href=\"/ko/6.1/ref/request-response/#django.http.HttpRequest.META\" title=\"django.http.HttpRequest.META\"><code class=\"xref py py-attr docutils literal notranslate\"><span class=\"pre\">request.META</span></code></a> (as <code class=\"docutils literal notranslate\"><span class=\"pre\">REMOTE_USER</span></code> when\nsupplied as an environment variable, as in WSGI, or <code class=\"docutils literal notranslate\"><span class=\"pre\">HTTP_REMOTE_USER</span></code> when\nsupplied via an HTTP header, as in ASGI). Django can be configured to make use\nof the <code class=\"docutils literal notranslate\"><span class=\"pre\">REMOTE_USER</span></code> value using the <code class=\"docutils literal notranslate\"><span class=\"pre\">RemoteUserMiddleware</span></code> or\n<code class=\"docutils literal notranslate\"><span class=\"pre\">PersistentRemoteUserMiddleware</span></code>, and\n<a class=\"reference internal\" href=\"/ko/6.1/ref/contrib/auth/#django.contrib.auth.backends.RemoteUserBackend\" title=\"django.contrib.auth.backends.RemoteUserBackend\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">RemoteUserBackend</span></code></a> classes found in\n<a class=\"reference internal\" href=\"/ko/6.1/topics/auth/#module-django.contrib.auth\" title=\"django.contrib.auth: Django's authentication framework.\"><code class=\"xref py py-mod docutils literal notranslate\"><span class=\"pre\">django.contrib.auth</span></code></a>.</p>\n<section id=\"configuration\">\n<h2>설정<a class=\"heading-anchor\" href=\"#configuration\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>우선,  <a class=\"reference internal\" href=\"/ko/6.1/ref/middleware/#django.contrib.auth.middleware.AuthenticationMiddleware\" title=\"django.contrib.auth.middleware.AuthenticationMiddleware\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">django.contrib.auth.middleware.AuthenticationMiddleware</span></code></a>를 설정하기 전에 <a class=\"reference internal\" href=\"/ko/6.1/ref/settings/#std-setting-MIDDLEWARE\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">MIDDLEWARE</span></code></a>에 <a class=\"reference internal\" href=\"/ko/6.1/ref/middleware/#django.contrib.auth.middleware.RemoteUserMiddleware\" title=\"django.contrib.auth.middleware.RemoteUserMiddleware\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">django.contrib.auth.middleware.RemoteUserMiddleware</span></code></a>를 추가해야 합니다.</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"n\">MIDDLEWARE</span> <span class=\"o\">=</span> <span class=\"p\">[</span>\n    <span class=\"s2\">&quot;...&quot;</span><span class=\"p\">,</span>\n    <span class=\"s2\">&quot;django.contrib.auth.middleware.AuthenticationMiddleware&quot;</span><span class=\"p\">,</span>\n    <span class=\"s2\">&quot;django.contrib.auth.middleware.RemoteUserMiddleware&quot;</span><span class=\"p\">,</span>\n    <span class=\"s2\">&quot;...&quot;</span><span class=\"p\">,</span>\n<span class=\"p\">]</span>\n</code></pre></div>\n<p>그 다음 , <a class=\"reference internal\" href=\"/ko/6.1/ref/settings/#std-setting-AUTHENTICATION_BACKENDS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">AUTHENTICATION_BACKENDS</span></code></a> 세팅에 있는 <a class=\"reference internal\" href=\"/ko/6.1/ref/contrib/auth/#django.contrib.auth.backends.ModelBackend\" title=\"django.contrib.auth.backends.ModelBackend\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">ModelBackend</span></code></a>를 <a class=\"reference internal\" href=\"/ko/6.1/ref/contrib/auth/#django.contrib.auth.backends.RemoteUserBackend\" title=\"django.contrib.auth.backends.RemoteUserBackend\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">RemoteUserBackend</span></code></a>로 바꿔야 합니다.</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"n\">AUTHENTICATION_BACKENDS</span> <span class=\"o\">=</span> <span class=\"p\">[</span>\n    <span class=\"s2\">&quot;django.contrib.auth.backends.RemoteUserBackend&quot;</span><span class=\"p\">,</span>\n<span class=\"p\">]</span>\n</code></pre></div>\n<p>With this setup, <code class=\"docutils literal notranslate\"><span class=\"pre\">RemoteUserMiddleware</span></code> will detect the username in\n<code class=\"docutils literal notranslate\"><span class=\"pre\">request.META['REMOTE_USER']</span></code> (or <code class=\"docutils literal notranslate\"><span class=\"pre\">request.META['HTTP_REMOTE_USER']</span></code> under\nASGI) and will authenticate and auto-login that user\nusing the <a class=\"reference internal\" href=\"/ko/6.1/ref/contrib/auth/#django.contrib.auth.backends.RemoteUserBackend\" title=\"django.contrib.auth.backends.RemoteUserBackend\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">RemoteUserBackend</span></code></a>.</p>\n<p>이 설정은 인증을 기본 <code class=\"docutils literal notranslate\"><span class=\"pre\">ModelBackend</span></code>로 사용하지 못하게 합니다. 그 말은 만약 <code class=\"docutils literal notranslate\"><span class=\"pre\">REMOTE_USER</span></code> 값이 설정되어 있지 않으면 Django의 관리 인터페이스를 사용한다 하더라도 사용자는 로그인할 수 없다는 것입니다. <code class=\"docutils literal notranslate\"><span class=\"pre\">django.contrib.auth.backends.ModelBackend</span></code>를 <code class=\"docutils literal notranslate\"><span class=\"pre\">AUTHENTICATION_BACKENDS</span></code> 리스트에 추가하면 <code class=\"docutils literal notranslate\"><span class=\"pre\">REMOTE_USER</span></code>가 없을 경우``ModelBackend``로 대체하여 이 문제를 해결할 수 있습니다.</p>\n<p><code class=\"docutils literal notranslate\"><span class=\"pre\">contrib.admin</span></code>의 뷰와 <a class=\"reference internal\" href=\"/ko/6.1/ref/django-admin/#django-admin-createsuperuser\"><code class=\"xref std std-djadmin docutils literal notranslate\"><span class=\"pre\">createsuperuser</span></code></a> 관리 명령과 같은 Django의 사용자 관리는 원격 사용자와 통합할 수 없습니다. 이 인터페이스들은 <code class=\"docutils literal notranslate\"><span class=\"pre\">AUTHENTICATION_BACKENDS</span></code>와 상관없이 데이터페이스에 저장된 사용자와만 작동합니다.</p>\n<aside class=\"admonition admonition-note\" role=\"note\">\n<p class=\"admonition-title\">참고</p>\n<p><code class=\"docutils literal notranslate\"><span class=\"pre\">RemoteUserBackend</span></code>는 <code class=\"docutils literal notranslate\"><span class=\"pre\">ModelBackend</span></code>를 상속하기 때문에 독자는 <code class=\"docutils literal notranslate\"><span class=\"pre\">ModelBackend</span></code>에서 구현된 권한 확인을 모두 그대로 가지고 있습니다.</p>\n<p>Users with <a class=\"reference internal\" href=\"/ko/6.1/ref/contrib/auth/#django.contrib.auth.models.User.is_active\" title=\"django.contrib.auth.models.User.is_active\"><code class=\"xref py py-attr docutils literal notranslate\"><span class=\"pre\">is_active=False</span></code></a> won’t be allowed to\nauthenticate. Use\n<a class=\"reference internal\" href=\"/ko/6.1/ref/contrib/auth/#django.contrib.auth.backends.AllowAllUsersRemoteUserBackend\" title=\"django.contrib.auth.backends.AllowAllUsersRemoteUserBackend\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">AllowAllUsersRemoteUserBackend</span></code></a> if\nyou want to allow them to.</p>\n</aside>\n<p>인증 메커니즘이 <code class=\"docutils literal notranslate\"><span class=\"pre\">REMOTE_USER</span></code> 대신 맞춤 HTTP 헤더를 사용하는 경우 <code class=\"docutils literal notranslate\"><span class=\"pre\">RemoteUserMiddleware``의</span> <span class=\"pre\">하위</span> <span class=\"pre\">클래스를</span> <span class=\"pre\">만들고</span> <span class=\"pre\">``header</span></code> 속성을 원하는 <code class=\"docutils literal notranslate\"><span class=\"pre\">request.META</span></code> 키로 설정할 수 있습니다. 예시는 다음과 같습니다.</p>\n<figure class=\"code-block code-block-captioned\" data-language=\"python\"><figcaption class=\"code-block-caption\"><code class=\"docutils literal notranslate\"><span class=\"pre\">mysite/middleware.py</span></code></figcaption>\n<div class=\"code-block-toolbar\"><span class=\"code-block-language\">Python</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Python code\"><code> <span class=\"kn\">from</span><span class=\"w\"> </span><span class=\"nn\">django.contrib.auth.middleware</span><span class=\"w\"> </span><span class=\"kn\">import</span> <span class=\"n\">RemoteUserMiddleware</span>\n\n\n <span class=\"k\">class</span><span class=\"w\"> </span><span class=\"nc\">CustomHeaderRemoteUserMiddleware</span><span class=\"p\">(</span><span class=\"n\">RemoteUserMiddleware</span><span class=\"p\">):</span>\n     <span class=\"n\">header</span> <span class=\"o\">=</span> <span class=\"s2\">&quot;HTTP_AUTHUSER&quot;</span>\n</code></pre></figure>\n<p>이렇게 만든 맞춤 미들웨어는 <a class=\"reference internal\" href=\"/ko/6.1/ref/settings/#std-setting-MIDDLEWARE\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">MIDDLEWARE</span></code></a> 설정에서 <a class=\"reference internal\" href=\"/ko/6.1/ref/middleware/#django.contrib.auth.middleware.RemoteUserMiddleware\" title=\"django.contrib.auth.middleware.RemoteUserMiddleware\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">django.contrib.auth.middleware.RemoteUserMiddleware</span></code></a> 대신 사용됩니다:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"n\">MIDDLEWARE</span> <span class=\"o\">=</span> <span class=\"p\">[</span>\n    <span class=\"s2\">&quot;...&quot;</span><span class=\"p\">,</span>\n    <span class=\"s2\">&quot;django.contrib.auth.middleware.AuthenticationMiddleware&quot;</span><span class=\"p\">,</span>\n    <span class=\"s2\">&quot;mysite.middleware.CustomHeaderRemoteUserMiddleware&quot;</span><span class=\"p\">,</span>\n    <span class=\"s2\">&quot;...&quot;</span><span class=\"p\">,</span>\n<span class=\"p\">]</span>\n</code></pre></div>\n<aside class=\"admonition admonition-warning\" role=\"note\">\n<p class=\"admonition-title\">경고</p>\n<p><code class=\"docutils literal notranslate\"><span class=\"pre\">RemoteUserMiddleware</span></code> must not be deployed in configurations where a\nclient can supply the header. You must be sure that your web server or\nreverse proxy always sets or strips that header based on the appropriate\nauthentication checks, never permitting an end user to submit a fake (or\n“spoofed”) header value.</p>\n<p>Since the HTTP headers <code class=\"docutils literal notranslate\"><span class=\"pre\">X-Auth-User</span></code> and <code class=\"docutils literal notranslate\"><span class=\"pre\">X-Auth_User</span></code> (for example)\nboth normalize to the <code class=\"docutils literal notranslate\"><span class=\"pre\">HTTP_X_AUTH_USER</span></code> key in <code class=\"docutils literal notranslate\"><span class=\"pre\">request.META</span></code>, you\nmust also check that your web server doesn’t allow a spoofed header using\nunderscores in place of dashes.</p>\n<p>Under WSGI, this warning doesn’t apply to <code class=\"docutils literal notranslate\"><span class=\"pre\">RemoteUserMiddleware</span></code> in its\ndefault configuration with <code class=\"docutils literal notranslate\"><span class=\"pre\">header</span> <span class=\"pre\">=</span> <span class=\"pre\">&quot;REMOTE_USER&quot;</span></code>, since a key that\ndoesn’t start with <code class=\"docutils literal notranslate\"><span class=\"pre\">HTTP_</span></code> in <code class=\"docutils literal notranslate\"><span class=\"pre\">request.META</span></code> can only be set by your\nWSGI server, not directly from an HTTP request header.</p>\n<p>This warning applies under ASGI in all configurations, because there is\nno equivalent for a WSGI server’s ability to place a trusted value in the\nenviron. ASGI deployments <em>must</em> use a reverse proxy as described above\nwhen using this middleware.</p>\n</aside>\n<p>만약 독자가 더 많은 제어를 필요로 할 경우, <a class=\"reference internal\" href=\"/ko/6.1/ref/contrib/auth/#django.contrib.auth.backends.RemoteUserBackend\" title=\"django.contrib.auth.backends.RemoteUserBackend\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">RemoteUserBackend</span></code></a>를 상속하는 인증 백엔드를 스스로 만들어 하나 이상의 속성과 메소드를 오버라이드할 수 있습니다.</p>\n</section>\n<section id=\"using-remote-user-on-login-pages-only\">\n<span id=\"persistent-remote-user-middleware-howto\"></span><h2><code class=\"docutils literal notranslate\"><span class=\"pre\">REMOTE_USER</span></code>는 로그인 페이지에서만 사용할 수 있습니다.<a class=\"heading-anchor\" href=\"#using-remote-user-on-login-pages-only\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>인증 미들웨어인 <code class=\"docutils literal notranslate\"><span class=\"pre\">RemoteUserMiddleware</span></code>는 HTTP 요청 헤더인 <code class=\"docutils literal notranslate\"><span class=\"pre\">REMOTE_USER</span></code>가 모든 인증된 요청과 함께 존재한다는 것을 가정합니다. 이것은 Basic HTTP Auth가 <code class=\"docutils literal notranslate\"><span class=\"pre\">htpasswd</span></code> 또는 기타 간단한 메커니즘들과 함께일 때 기대거나 실용적이지만,  Negotiate(GSSAPI / Kerberos) 또는 기타 자원 집약적인 인증 방법과 함께 일 때는, 프런트엔드 HTTP 서버에서의 인증은 일반적으로 하나 또는 몇 개의 로그인 URL을 설정해야하고, 인증이 성공하면 응용 프로그램은 인증된 세션 자체가 유지 관리된다라는 조건이여야합니다.</p>\n<p><a class=\"reference internal\" href=\"/ko/6.1/ref/middleware/#django.contrib.auth.middleware.PersistentRemoteUserMiddleware\" title=\"django.contrib.auth.middleware.PersistentRemoteUserMiddleware\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">PersistentRemoteUserMiddleware</span></code></a>는 사용 사례에 대한 지원을 제공합니다. 이것은 사용자에 의하여 명시적으로 로그아웃할 때까지 인증된 세션을 유지 관리할 것 입니다. 이 클래스는 위의 문서에서 <a class=\"reference internal\" href=\"/ko/6.1/ref/middleware/#django.contrib.auth.middleware.RemoteUserMiddleware\" title=\"django.contrib.auth.middleware.RemoteUserMiddleware\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">RemoteUserMiddleware</span></code></a> 일시 대체품으로 사용되어질 수 있습니다.</p>\n</section>","rootId":"how-to-authenticate-using-remote-user","toc":[{"title":"설정","anchor":"configuration","children":[]},{"title":"REMOTE_USER는 로그인 페이지에서만 사용할 수 있습니다.","anchor":"using-remote-user-on-login-pages-only","children":[]}],"breadcrumbs":[{"docname":"howto/index","title":"How-to 가이드","url":"/ko/6.1/howto/"}],"prev":{"docname":"howto/static-files/deployment","title":"정적 파일을 배포하는 방법","url":"/ko/6.1/howto/static-files/deployment/"},"next":{"docname":"howto/csp","title":"Django의 콘텐츠 보안 정책을 사용하는 방법","url":"/ko/6.1/howto/csp/"},"formats":{"html":"/ko/6.1/howto/auth-remote-user/","markdown":"/ko/6.1/howto/auth-remote-user.md","json":"/ko/6.1/howto/auth-remote-user.json"},"source":"https://github.com/django/django/blob/stable/6.1.x/docs/howto/auth-remote-user.txt","official":"https://docs.djangoproject.com/ko/6.1/howto/auth-remote-user/","inVersions":["6.1","6.0","5.2","5.1","5.0","4.2","4.1","4.0","3.2","3.1","3.0","2.2","2.1","2.0","1.11"],"inLocales":["en","sv","zh-hans","ga","fr","ja","id","it","pt-br","ko","es","el","pl"]}