yii2 restful 风格搭建(二)

yii2 restful 风格搭建(二)接口认证

流过昼夜 提交于 2019-12-01 00:35:45
做完了基本的 restful 搭建,就需要接口认证和定义返回码了 一、yii2 支持的 3种认证方式 1、HTTP 基本认证: \yii\filters\auth\HttpBasicAuth 支持两种认证方式,输入用户名和密码和只输入用户名(或 access_token) (1)默认是只输入用户名(或acdess_token) The default implementation of HttpBasicAuth uses the [[\yii\web\User::loginByAccessToken()|loginByAccessToken()]] method of the `user` application component and only passes the user name. This implementation is used for authenticating API clients. 只输入用户名认证需要在你的 user identity class 类中实现 findIdentityByAccessToken() 方法 (2)如果需要验证用户名和密码,HttpBasicAuth 中的注释中也说明了配置方法 public function behaviors() { return [ 'basicAuth' => [ 'class' => \yii