# Basic Auth Configuration

The `basic-auth` plugin provides basic access authentication, requiring clients to authenticate before accessing upstream resources, enhancing API security.<!-- --> <!-- -->Configuration covers credential fields and route and service fields.

## Parameters[​](#parameters "Direct link to Parameters")

See plugin [common configurations](https://docs.api7.ai/apisix/reference/plugin-common-configurations.md) for configuration options available to all plugins.

### Credentials[​](#credentials "Direct link to Credentials")

The following are plugin attributes available for configurations on [credentials](https://docs.api7.ai/apisix/key-concepts/credentials.md).

* username

  string

  required

  ***

  Unique basic auth username for a consumer.

* password

  string

  required

  ***

  Basic auth password for the consumer.

  In API7 Enterprise 3.9.20 and 3.10.7, and in APISIX 3.19.0, configuration validation rejects empty passwords, and passwords containing colons are accepted. Following RFC 7617, everything after the first colon of the decoded credentials is taken as the password. Whitespace is still stripped from both halves of the decoded credentials before they are compared, so a password containing spaces cannot be used.

  The password is encrypted with AES before being stored in etcd. You can also store it in an environment variable and reference it using the `$env://` prefix, or in a secret manager such as HashiCorp Vault's [KV secrets engine](https://developer.hashicorp.com/vault/docs/secrets/kv), and reference it using the `$secret://` prefix. For more information, see [secrets](https://docs.api7.ai/apisix/key-concepts/secrets.md).

  A `$env://` or `$secret://` reference that resolves to an empty value still passes configuration validation, because references are resolved at request time. In API7 Enterprise 3.9.20 and 3.10.7, and in APISIX 3.19.0, Basic Auth cannot authenticate that consumer. The request returns HTTP 401 unless an anonymous consumer or another method configured through `multi-auth` allows it.

### Routes or Services[​](#routes-or-services "Direct link to Routes or Services")

The following are plugin attributes available for configurations on [routes](https://docs.api7.ai/apisix/key-concepts/routes.md) or [services](https://docs.api7.ai/apisix/key-concepts/services.md).

* hide\_credentials

  boolean

  default: `false`

  ***

  If true, do not pass the authorization request header to upstream services.

* anonymous\_consumer

  string

  ***

  Anonymous consumer name. If configured, allow anonymous users to bypass the authentication. See [Rate Limit with Anonymous Consumer](https://docs.api7.ai/hub/basic-auth.md#rate-limit-with-anonymous-consumer) for more details.

* realm

  string

  default: `basic`

  ***

  Realm in the [`WWW-Authenticate`](https://datatracker.ietf.org/doc/html/rfc7235#section-4.1) response header returned with a `401 Unauthorized` response due to authentication failure. For example:

  * If `realm` is set to `basic-auth`, the 401 response will include the following header:

    ```
    WWW-Authenticate: Basic realm="basic-auth"
    ```

  * If `realm` is not configured, the 401 response will include the following header:

    ```
    WWW-Authenticate: Basic realm="basic"
    ```

  This parameter is available in API7 Enterprise version 3.9.2 and later, and in Apache APISIX version 3.15.0 and later.
