REST API无需身份验证方法即可运行.现在,我想通过移动应用程序对API请求的OAuth2身份验证验证REST API.我试过yii2指南,但它对我不起作用.
基本上移动用户需要使用用户名和密码登录,如果用户名和密码正确,则用户需要登录,并且需要使用令牌进一步验证API请求.
我是否需要像这样创建自定义OAuth 2客户端? 创建自己的auth客户端
用户表中的access_token字段为空.我需要手动保存吗?如何将access_token作为响应返回?
用户是否有任何理由同时使用这三种方法(HttpBasicAuth,HttpBearerAuth,QueryParamAuth),为什么?怎么样?
我的应用程序文件夹结构如下所示.
api
-config
-modules
--v1
---controllers
---models
-runtime
-tests
-web
backend
common
console
environments
frontend
Run Code Online (Sandbox Code Playgroud)
API \模块\ V1\Module.php
namespace api\modules\v1;
class Module extends \yii\base\Module
{
public $controllerNamespace = 'api\modules\v1\controllers';
public function init()
{
parent::init();
\Yii::$app->user->enableSession = false;
}
}
Run Code Online (Sandbox Code Playgroud)
API \模块\ V1 \控制器\ CountryController.php
namespace api\modules\v1\controllers;
use Yii;
use yii\rest\ActiveController;
use common\models\LoginForm;
use common\models\User;
use yii\filters\auth\CompositeAuth;
use yii\filters\auth\HttpBasicAuth;
use yii\filters\auth\HttpBearerAuth;
use yii\filters\auth\QueryParamAuth;
/**
* Country Controller API
*
* @author Budi …Run Code Online (Sandbox Code Playgroud) REST API无需身份验证方法即可运行.现在,我想通过移动应用程序对API请求进行HTTP基本身份验证来验证REST API.我试过yii2指南,但它对我不起作用.
基本上移动用户需要使用用户名和密码登录,如果用户名和密码正确,则用户需要登录,并且需要使用令牌进一步验证API请求.
当我调试findIdentityByAccessToken()函数时,$ token等于用户名.Postman扩展用于检查HTTP Basic请求.用户表中的access_token字段为空.我需要手动保存吗?如何将access_token作为响应返回?
这三种方法(HttpBasicAuth,HttpBearerAuth,QueryParamAuth)是否有任何原因,为什么?怎么样?
我的应用程序文件夹结构如下所示.
api
-config
-modules
--v1
---controllers
---models
-runtime
-tests
-web
backend
common
console
environments
frontend
Run Code Online (Sandbox Code Playgroud)
API \模块\ V1\Module.php
namespace api\modules\v1;
class Module extends \yii\base\Module
{
public $controllerNamespace = 'api\modules\v1\controllers';
public function init()
{
parent::init();
\Yii::$app->user->enableSession = false;
}
}
Run Code Online (Sandbox Code Playgroud)
API \模块\ V1 \控制器\ CountryController.php
namespace api\modules\v1\controllers;
use Yii;
use yii\rest\ActiveController;
use common\models\LoginForm;
use common\models\User;
use yii\filters\auth\CompositeAuth;
use yii\filters\auth\HttpBasicAuth;
use yii\filters\auth\HttpBearerAuth;
use yii\filters\auth\QueryParamAuth;
class CountryController extends ActiveController
{
public $modelClass = 'api\modules\v1\models\Country';
public …Run Code Online (Sandbox Code Playgroud) 我在尝试导航到angualr中的' http:// localhost:4200/dashboard '延迟加载路径时遇到此错误,angualr-cli 6.0.0
错误错误:未捕获(在承诺中):错误:找不到模块"app/dashboard/dashboard.module".错误:找不到模块"app/dashboard/dashboard.module".at $ _lazy_route_resource lazy namespace object:5
const routes: Routes = [
{
path: 'login',
loadChildren: 'app/login/login.module#LoginModule',
},
{
path: '',
component: MasterComponent,
children: [
{
path: 'dashboard',
loadChildren: 'app/dashboard/dashboard.module#DashboardModule'
}
],
},
{
path: '**',
redirectTo: 'login
}
];
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule],
providers: []
})
export class AppRoutingModule {
}
Run Code Online (Sandbox Code Playgroud) 在以前的版本中,可以使用.angular-cli.json禁用spec.ts,如下所示.有什么办法在版本6.0.0中使用angular.json吗?
"defaults": {
"component": {
"spec": false
},
"service": {
"spec": false
},
...
}
Run Code Online (Sandbox Code Playgroud)