Class yii\filters\auth\CompositeAuth
CompositeAuth 是一个同时支持多种身份验证方法的操作筛选器。
CompositeAuth 包含的身份验证方法是通过 $authMethods 配置的, 这是受支持的身份验证类配置的列表。
下面的示例演示如何支持三种身份验证方法:
public function behaviors()
{
return [
'compositeAuth' => [
'class' => \yii\filters\auth\CompositeAuth::className(),
'authMethods' => [
\yii\filters\auth\HttpBasicAuth::className(),
\yii\filters\auth\QueryParamAuth::className(),
],
],
];
}
公共属性
| 属性 | 类型 | 描述 | 被定义在 |
|---|---|---|---|
| $authMethods | array | 支持的身份验证方法。此属性应采用受支持 的身份验证方法列表,每个都由身份验证类或配置表示。 如果此属性为空,则不会执行任何身份验证。 注意,auth 方法类必须实现 yii\filters\auth\AuthInterface 接口。 | yii\filters\auth\CompositeAuth |
| $except | array | List of action IDs that this filter should not apply to. | yii\base\ActionFilter |
| $only | array | List of action IDs that this filter should apply to. | yii\base\ActionFilter |
| $optional | array | 此筛选器将应用于的操作行为 IDs 的数组列表,但是身份验证失败不会导致错误。 它可能被用于行动,那是允许公开的,但是返回一些已验证用户的附加数据。 默认空,意思是不可选认证的任何行动。 Since version 2. | yii\filters\auth\AuthMethod |
| $owner | yii\base\Component|null | The owner of this behavior | yii\base\Behavior |
| $request | yii\web\Request | 当前请求。如果没有设置,这个请求将使用应用程序组件。 | yii\filters\auth\AuthMethod |
| $response | yii\web\Response | 要发送的响应。如果没有设置,这个响应将使用应用程序组件。 | yii\filters\auth\AuthMethod |
| $user | yii\web\User | 表示用户身份验证状态的用户对象。如果没有设置,这个用户将使用应用程序组件。 | yii\filters\auth\AuthMethod |
公共方法
| 方法 | 描述 | 被定义在 |
|---|---|---|
| __call() | Calls the named method which is not a class method. | yii\base\BaseObject |
| __construct() | Constructor. | yii\base\BaseObject |
| __get() | Returns the value of an object property. | yii\base\BaseObject |
| __isset() | Checks if a property is set, i.e. defined and not null. | yii\base\BaseObject |
| __set() | Sets value of an object property. | yii\base\BaseObject |
| __unset() | Sets an object property to null. | yii\base\BaseObject |
| afterAction() | 执行动作后立即调用此方法。 您可以覆盖此方法以对操作执行一些后处理。 | yii\base\ActionFilter |
| afterFilter() | yii\base\ActionFilter | |
| attach() | Attaches the behavior object to the component. | yii\base\Behavior |
| authenticate() | 对当前用户进行身份验证。 | yii\filters\auth\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. | yii\filters\auth\CompositeAuth |
| beforeFilter() | yii\base\ActionFilter | |
| canGetProperty() | Returns a value indicating whether a property can be read. | yii\base\BaseObject |
| canSetProperty() | Returns a value indicating whether a property can be set. | yii\base\BaseObject |
| challenge() | 在身份验证失败时产生质询。 例如,一些适当的 HTTP headers 可能会生成。 | yii\filters\auth\CompositeAuth |
| className() | Returns the fully qualified name of this class. | yii\base\BaseObject |
| detach() | Detaches the behavior object from the component. | yii\base\Behavior |
| events() | Declares event handlers for the $owner's events. | yii\base\Behavior |
| handleFailure() | 处理身份验证失败。 该实现通常应抛出未经授权的 UnauthorizedHttpException 异常以指示身份验证失败。 | yii\filters\auth\AuthMethod |
| hasMethod() | Returns a value indicating whether a method is defined. | yii\base\BaseObject |
| hasProperty() | Returns a value indicating whether a property is defined. | yii\base\BaseObject |
| init() | Initializes the object. | yii\base\BaseObject |
受保护的方法
| 方法 | 描述 | 被定义在 |
|---|---|---|
| getActionId() | 通过将 yii\base\Action::$uniqueId 转换为相对于模块的 ID 来返回动作 ID。 | yii\base\ActionFilter |
| isActive() | 返回一个值,该值指示过滤器对于给定操作是否处于活动状态。 | yii\base\ActionFilter |
| isOptional() | 检查,给定操作的身份验证是否可选。 | yii\filters\auth\AuthMethod |
属性详情
支持的身份验证方法。此属性应采用受支持 的身份验证方法列表,每个都由身份验证类或配置表示。
如果此属性为空,则不会执行任何身份验证。
注意,auth 方法类必须实现 yii\filters\auth\AuthInterface 接口。
方法详情
对当前用户进行身份验证。
| public yii\web\IdentityInterface authenticate($user, $request, $response) | ||
| $user | yii\web\User | |
| $request | yii\web\Request | |
| $response | yii\web\Response | |
| return | yii\web\IdentityInterface | 已验证的用户标识。如果不提供身份验证信息,则返回空。 |
|---|---|---|
| throws | yii\web\UnauthorizedHttpException | 如果提供的身份验证信息无效。 |
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.
| public boolean beforeAction($action) | ||
| $action | yii\base\Action | 要执行的动作。 |
| return | boolean | 该动作是否应继续执行。 |
|---|---|---|
在身份验证失败时产生质询。 例如,一些适当的 HTTP headers 可能会生成。
| public void challenge($response) | ||
| $response | yii\web\Response | |