---
title: "“REMOTE_USER”를 이용해 인증하는 방법"
version: 6.1
locale: ko
source: https://docs.djangoproject.com/ko/6.1/howto/auth-remote-user/
canonical: https://djangodocs.dev/ko/6.1/howto/auth-remote-user/
---
# “REMOTE\_USER”를 이용해 인증하는 방법

This document describes how to make use of external authentication sources in
your Django applications. This type of authentication solution is typically
seen on intranet sites, with single sign-on solutions such as IIS and
Integrated Windows Authentication or Apache and [mod\_authnz\_ldap](https://httpd.apache.org/docs/current/mod/mod_authnz_ldap.html), [CAS](https://www.apereo.org/projects/cas),
[WebAuth](https://uit.stanford.edu/service/authentication), [mod\_auth\_sspi](https://sourceforge.net/projects/mod-auth-sspi), etc.

When the web server takes care of authentication it typically provides the
authenticated user as `REMOTE_USER`. In Django, this value is made available
in [`request.META`](/ko/6.1/ref/request-response/#django.http.HttpRequest.META) (as `REMOTE_USER` when
supplied as an environment variable, as in WSGI, or `HTTP_REMOTE_USER` when
supplied via an HTTP header, as in ASGI). Django can be configured to make use
of the `REMOTE_USER` value using the `RemoteUserMiddleware` or
`PersistentRemoteUserMiddleware`, and
[`RemoteUserBackend`](/ko/6.1/ref/contrib/auth/#django.contrib.auth.backends.RemoteUserBackend) classes found in
[`django.contrib.auth`](/ko/6.1/topics/auth/#module-django.contrib.auth).

## 설정

우선,  [`django.contrib.auth.middleware.AuthenticationMiddleware`](/ko/6.1/ref/middleware/#django.contrib.auth.middleware.AuthenticationMiddleware)를 설정하기 전에 [`MIDDLEWARE`](/ko/6.1/ref/settings/#std-setting-MIDDLEWARE)에 [`django.contrib.auth.middleware.RemoteUserMiddleware`](/ko/6.1/ref/middleware/#django.contrib.auth.middleware.RemoteUserMiddleware)를 추가해야 합니다.

```
MIDDLEWARE = [
    "...",
    "django.contrib.auth.middleware.AuthenticationMiddleware",
    "django.contrib.auth.middleware.RemoteUserMiddleware",
    "...",
]
```

그 다음 , [`AUTHENTICATION_BACKENDS`](/ko/6.1/ref/settings/#std-setting-AUTHENTICATION_BACKENDS) 세팅에 있는 [`ModelBackend`](/ko/6.1/ref/contrib/auth/#django.contrib.auth.backends.ModelBackend)를 [`RemoteUserBackend`](/ko/6.1/ref/contrib/auth/#django.contrib.auth.backends.RemoteUserBackend)로 바꿔야 합니다.

```
AUTHENTICATION_BACKENDS = [
    "django.contrib.auth.backends.RemoteUserBackend",
]
```

With this setup, `RemoteUserMiddleware` will detect the username in
`request.META['REMOTE_USER']` (or `request.META['HTTP_REMOTE_USER']` under
ASGI) and will authenticate and auto-login that user
using the [`RemoteUserBackend`](/ko/6.1/ref/contrib/auth/#django.contrib.auth.backends.RemoteUserBackend).

이 설정은 인증을 기본 `ModelBackend`로 사용하지 못하게 합니다. 그 말은 만약 `REMOTE_USER` 값이 설정되어 있지 않으면 Django의 관리 인터페이스를 사용한다 하더라도 사용자는 로그인할 수 없다는 것입니다. `django.contrib.auth.backends.ModelBackend`를 `AUTHENTICATION_BACKENDS` 리스트에 추가하면 `REMOTE_USER`가 없을 경우\`\`ModelBackend\`\`로 대체하여 이 문제를 해결할 수 있습니다.

`contrib.admin`의 뷰와 [`createsuperuser`](/ko/6.1/ref/django-admin/#django-admin-createsuperuser) 관리 명령과 같은 Django의 사용자 관리는 원격 사용자와 통합할 수 없습니다. 이 인터페이스들은 `AUTHENTICATION_BACKENDS`와 상관없이 데이터페이스에 저장된 사용자와만 작동합니다.

> **Note**
>
> `RemoteUserBackend`는 `ModelBackend`를 상속하기 때문에 독자는 `ModelBackend`에서 구현된 권한 확인을 모두 그대로 가지고 있습니다.
>
> Users with [`is_active=False`](/ko/6.1/ref/contrib/auth/#django.contrib.auth.models.User.is_active) won’t be allowed to
> authenticate. Use
> [`AllowAllUsersRemoteUserBackend`](/ko/6.1/ref/contrib/auth/#django.contrib.auth.backends.AllowAllUsersRemoteUserBackend) if
> you want to allow them to.

인증 메커니즘이 `REMOTE_USER` 대신 맞춤 HTTP 헤더를 사용하는 경우 ```RemoteUserMiddleware``의 하위 클래스를 만들고 ``header``` 속성을 원하는 `request.META` 키로 설정할 수 있습니다. 예시는 다음과 같습니다.

*`mysite/middleware.py`*

```python
 from django.contrib.auth.middleware import RemoteUserMiddleware

 class CustomHeaderRemoteUserMiddleware(RemoteUserMiddleware):
     header = "HTTP_AUTHUSER"
```

이렇게 만든 맞춤 미들웨어는 [`MIDDLEWARE`](/ko/6.1/ref/settings/#std-setting-MIDDLEWARE) 설정에서 [`django.contrib.auth.middleware.RemoteUserMiddleware`](/ko/6.1/ref/middleware/#django.contrib.auth.middleware.RemoteUserMiddleware) 대신 사용됩니다:

```
MIDDLEWARE = [
    "...",
    "django.contrib.auth.middleware.AuthenticationMiddleware",
    "mysite.middleware.CustomHeaderRemoteUserMiddleware",
    "...",
]
```

> **Warning**
>
> `RemoteUserMiddleware` must not be deployed in configurations where a
> client can supply the header. You must be sure that your web server or
> reverse proxy always sets or strips that header based on the appropriate
> authentication checks, never permitting an end user to submit a fake (or
> “spoofed”) header value.
>
> Since the HTTP headers `X-Auth-User` and `X-Auth_User` (for example)
> both normalize to the `HTTP_X_AUTH_USER` key in `request.META`, you
> must also check that your web server doesn’t allow a spoofed header using
> underscores in place of dashes.
>
> Under WSGI, this warning doesn’t apply to `RemoteUserMiddleware` in its
> default configuration with `header = "REMOTE_USER"`, since a key that
> doesn’t start with `HTTP_` in `request.META` can only be set by your
> WSGI server, not directly from an HTTP request header.
>
> This warning applies under ASGI in all configurations, because there is
> no equivalent for a WSGI server’s ability to place a trusted value in the
> environ. ASGI deployments *must* use a reverse proxy as described above
> when using this middleware.

만약 독자가 더 많은 제어를 필요로 할 경우, [`RemoteUserBackend`](/ko/6.1/ref/contrib/auth/#django.contrib.auth.backends.RemoteUserBackend)를 상속하는 인증 백엔드를 스스로 만들어 하나 이상의 속성과 메소드를 오버라이드할 수 있습니다.

## `REMOTE_USER`는 로그인 페이지에서만 사용할 수 있습니다.

인증 미들웨어인 `RemoteUserMiddleware`는 HTTP 요청 헤더인 `REMOTE_USER`가 모든 인증된 요청과 함께 존재한다는 것을 가정합니다. 이것은 Basic HTTP Auth가 `htpasswd` 또는 기타 간단한 메커니즘들과 함께일 때 기대거나 실용적이지만,  Negotiate(GSSAPI / Kerberos) 또는 기타 자원 집약적인 인증 방법과 함께 일 때는, 프런트엔드 HTTP 서버에서의 인증은 일반적으로 하나 또는 몇 개의 로그인 URL을 설정해야하고, 인증이 성공하면 응용 프로그램은 인증된 세션 자체가 유지 관리된다라는 조건이여야합니다.

[`PersistentRemoteUserMiddleware`](/ko/6.1/ref/middleware/#django.contrib.auth.middleware.PersistentRemoteUserMiddleware)는 사용 사례에 대한 지원을 제공합니다. 이것은 사용자에 의하여 명시적으로 로그아웃할 때까지 인증된 세션을 유지 관리할 것 입니다. 이 클래스는 위의 문서에서 [`RemoteUserMiddleware`](/ko/6.1/ref/middleware/#django.contrib.auth.middleware.RemoteUserMiddleware) 일시 대체품으로 사용되어질 수 있습니다.
