# AuthInterface

> AuthInterface is the interface that should be implemented by auth method classes.

[API reference](/docs/api/index.md) › [yii](/docs/api/yii/index.md) › [filters](/docs/api/yii/filters/index.md) › [auth](/docs/api/yii/filters/auth/index.md) › AuthInterface

| interface | `yii\filters\auth\AuthInterface` |
| --- | --- |
| Since | 2.0 |
| Source | [`framework/filters/auth/AuthInterface.php`](https://github.com/yiisoft/yii2/blob/22.0/framework/filters/auth/AuthInterface.php#L23) |

Implemented by 1 type:

- [`AuthMethod`](/docs/api/yii/filters/auth/authmethod/index.md)

AuthInterface is the interface that should be implemented by auth method classes.

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| [`authenticate()`](#method-authenticate) abstract | Authenticates the current user. | `AuthInterface` |
| [`challenge()`](#method-challenge) abstract | Generates challenges upon authentication failure. | `AuthInterface` |
| [`handleFailure()`](#method-handleFailure) abstract | Handles authentication failure. | `AuthInterface` |

## Method details

### authenticate() <span id="method-authenticate"></span>

```php
abstract public function authenticate(yii\web\User $user, yii\web\Request $request, yii\web\Response $response): yii\web\IdentityInterface|null
```

Authenticates the current user.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$user` | [`yii\web\User`](/docs/api/yii/web/user/index.md) |  |
| `$request` | [`yii\web\Request`](/docs/api/yii/web/request/index.md) |  |
| `$response` | [`yii\web\Response`](/docs/api/yii/web/response/index.md) |  |

**Returns**

[`yii\web\IdentityInterface`](/docs/api/yii/web/identityinterface/index.md)`|null`: The authenticated user identity. If authentication information is not provided, null will be returned.

**Throws**

- [`yii\web\UnauthorizedHttpException`](/docs/api/yii/web/unauthorizedhttpexception/index.md): if authentication information is provided but is invalid.

### challenge() <span id="method-challenge"></span>

```php
abstract public function challenge(yii\web\Response $response): mixed
```

Generates challenges upon authentication failure.

For example, some appropriate HTTP headers may be generated.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$response` | [`yii\web\Response`](/docs/api/yii/web/response/index.md) |  |

**Returns**

`mixed`

### handleFailure() <span id="method-handleFailure"></span>

```php
abstract public function handleFailure(yii\web\Response $response): mixed
```

Handles authentication failure.

The implementation should normally throw UnauthorizedHttpException to indicate authentication failure.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$response` | [`yii\web\Response`](/docs/api/yii/web/response/index.md) |  |

**Returns**

`mixed`

**Throws**

- [`yii\web\UnauthorizedHttpException`](/docs/api/yii/web/unauthorizedhttpexception/index.md)