小编Cha*_*nka的帖子

Yii 2 RESTful API使用OAuth2进行身份验证(Yii 2高级模板)

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)

api rest oauth-2.0 yii2 yii2-advanced-app

9
推荐指数
2
解决办法
6578
查看次数

Yii 2 RESTful API使用HTTP Basic进行身份验证(Yii 2高级模板)

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)

api rest basic-authentication yii2 yii2-advanced-app

8
推荐指数
1
解决办法
1万
查看次数

延迟加载在Angular 6中不起作用

我在尝试导航到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

6
推荐指数
2
解决办法
8391
查看次数

在Angular 6中生成没有*.spec.ts的组件

在以前的版本中,可以使用.angular-cli.json禁用spec.ts,如下所示.有什么办法在版本6.0.0中使用angular.json吗?

"defaults": {
    "component": { 
        "spec": false 
    },
    "service": { 
        "spec": false 
    },
    ...
}
Run Code Online (Sandbox Code Playgroud)

angular6

3
推荐指数
3
解决办法
8361
查看次数