定制 rob006/yii2-simple-auth-yii-authenticator 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

rob006/yii2-simple-auth-yii-authenticator

Composer 安装命令:

composer require rob006/yii2-simple-auth-yii-authenticator

包简介

Yii 2 extension that provides helper for authenticate Request from yii2-httpclient package.

README 文档

README

Yii 2 extension that provides helper for authenticate Request from yii2-httpclient package.

This is a simple helper for yii2-simple-auth which simplify authenticating Request object from official Yii 2 httpclient extension. Read yii2-simple-auth README to get more details about authentication process and configuration.

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require rob006/yii2-simple-auth-yii-authenticator

or add

"rob006/yii2-simple-auth-yii-authenticator": "^1.0"

to the require section of your composer.json file.

Usage

You can simply authenticate Request object from official Yii 2 httpclient by using YiiAuthenticator helper:

use yii\httpclient\Client;
use rob006\simpleauth\YiiAuthenticator as Authenticator;

$client = new Client();
$request = $client->createRequest()
	->setUrl('http://api.example.com/user/list/')
	->setData(['ids' => '1,2,3,4']);
$request = Authenticator::authenticate($request);
$response = $request->send();

By default Authenticator sends authentication token in the header of the request. Alternatively you can send it in GET or POST param of request. Be careful when you using POST method because this will set request method as POST and all data set by \yii\httpclient\Request::setData() will be sent as POST data and will not be included in the URL.

Authentication by GET param with custom secret key:

use yii\httpclient\Client;
use rob006\simpleauth\YiiAuthenticator as Authenticator;

$client = new Client();
$request = $client->createRequest()
	->setUrl('http://api.example.com/user/list/')
	->setData(['ids' => '1,2,3,4']);
$request = Authenticator::authenticate($request, Authenticator::METHOD_GET, 'mycustomsecretkey');
$response = $request->send();

Authentication by POST param:

use yii\httpclient\Client;
use rob006\simpleauth\YiiAuthenticator as Authenticator;

$client = new Client();
$request = $client->createRequest()
	->setUrl('http://api.example.com/user/list/?ids=1,2,3,4');
$request = Authenticator::authenticate($request, Authenticator::METHOD_POST);
$response = $request->send();

统计信息

  • 总下载量: 97
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 3
  • 依赖项目数: 0
  • 推荐数: 1

GitHub 信息

  • Stars: 2
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-08-21

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固