CompositeAuth
API reference › yii › filters › auth › CompositeAuth
CompositeAuth is an action filter that supports multiple authentication methods at the same time.
The authentication methods contained by CompositeAuth are configured via $authMethods,
which is a list of supported authentication class configurations.
The following example shows how to support three authentication methods:
public function behaviors(){ return [ 'compositeAuth' => [ 'class' => \yii\filters\auth\CompositeAuth::class, 'authMethods' => [ \yii\filters\auth\HttpBasicAuth::class, \yii\filters\auth\QueryParamAuth::class, ], ], ];}Properties
Section titled “Properties”| Property | Type | Description | Defined by |
|---|---|---|---|
$authMethods | list<class-string<AuthInterface>|AuthInterface>}> | The supported authentication methods. Default: []. | CompositeAuth |
$except | array | List of action IDs that this filter should not apply to. Default: []. | yii\ |
$only | array | List of action IDs that this filter should apply to. Default: []. | yii\ |
$optional | array | List of action IDs that this filter will be applied to, but auth failure will not lead to error. Default: []. Available since 2.0.7. | AuthMethod |
$owner | yii\ | The owner of this behavior Default: null. | yii\ |
$request | yii\| | The current request. Default: null. | AuthMethod |
$response | yii\| | The response to be sent. Default: null. | AuthMethod |
$user | yii\| | The user object representing the user authentication status. Default: null. | AuthMethod |
Methods
Section titled “Methods”| Method | Description | Defined by |
|---|---|---|
__construct() | Constructor. | yii\ |
__call() | Calls the named method which is not a class method. | yii\ |
__get() | Returns the value of an object property. | yii\ |
__isset() | Checks if a property is set, i.e. defined and not null. | yii\ |
__set() | Sets value of an object property. | yii\ |
__unset() | Sets an object property to null. | yii\ |
afterAction() | This method is invoked right after an action is executed. | yii\ |
afterFilter() | yii\ | |
attach() | Attaches the behavior object to the component. | yii\ |
authenticate() | Authenticates the current user. | CompositeAuth |
beforeAction() | This method is invoked right before an action is to be executed (after all possible filters.) You may override this method to do last-minute preparation for the action. | CompositeAuth |
beforeFilter() | yii\ | |
canGetProperty() | Returns a value indicating whether a property can be read. | yii\ |
canSetProperty() | Returns a value indicating whether a property can be set. | yii\ |
challenge() | Generates challenges upon authentication failure. | CompositeAuth |
className() static | Returns the fully qualified name of this class. | yii\ |
detach() | Detaches the behavior object from the component. | yii\ |
events() | Declares event handlers for the $owner’s events. | yii\ |
handleFailure() | Handles authentication failure. | AuthMethod |
hasMethod() | Returns a value indicating whether a method is defined. | yii\ |
hasProperty() | Returns a value indicating whether a property is defined. | yii\ |
init() | Initializes the object. | yii\ |
getActionId() protected | Returns an action ID by converting Action::$uniqueId into an ID relative to the module. | yii\ |
isActive() protected | Returns a value indicating whether the filter is active for the given action. | yii\ |
isOptional() protected | Checks, whether authentication is optional for the given action. | AuthMethod |
Property details
Section titled “Property details”$authMethods
Section titled “$authMethods ”public list<class-string<yii\filters\auth\AuthInterface>|array{class: class-string<yii\filters\auth\AuthInterface>}> $authMethods = []The supported authentication methods.
This property should take a list of supported authentication methods, each represented by an authentication class or configuration.
If this property is empty, no authentication will be performed.
Note that an auth method class must implement the AuthInterface interface.
Method details
Section titled “Method details”authenticate()
Section titled “authenticate() ”public function authenticate(mixed $user, mixed $request, mixed $response): yii\web\IdentityInterface|nullAuthenticates the current user.
Parameters
| Parameter | Type | Description |
|---|---|---|
$user | mixed | |
$request | mixed | |
$response | mixed |
Returns
yii\web\IdentityInterface|null: The authenticated user identity. If authentication information is not provided, null will be returned.
Throws
yii\web\UnauthorizedHttpException: if authentication information is provided but is invalid.
beforeAction()
Section titled “beforeAction() ”public function beforeAction(mixed $action): boolThis method is invoked right before an action is to be executed (after all possible filters.) You may override this method to do last-minute preparation for the action.
Parameters
| Parameter | Type | Description |
|---|---|---|
$action | mixed | The action to be executed. |
Returns
bool: Whether the action should continue to be executed.
challenge()
Section titled “challenge() ”public function challenge(mixed $response): mixedGenerates challenges upon authentication failure.
For example, some appropriate HTTP headers may be generated.
Parameters
| Parameter | Type | Description |
|---|---|---|
$response | mixed |
Returns
mixed