定制 indigophp/guardian 二次开发

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

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

indigophp/guardian

Composer 安装命令:

composer require indigophp/guardian

包简介

Simple and flexible authentication framework

关键字:

README 文档

README

Latest Version Software License Build Status Code Coverage Quality Score HHVM Status Total Downloads

Simple and flexible authentication framework.

Install

Via Composer

$ composer require indigophp/guardian

Usage

This library provides an easy way to authenticate any entity with OR without persisting and calling it "login".

A simple login example:

use Indigo\Guardian\Identifier\InMemory;
use Indigo\Guardian\Authenticator\UserPassword;
use Indigo\Guardian\Hasher\Plaintext;
use Indigo\Guardian\SessionAuth;
use Indigo\Guardian\Session\Native;

$identifier = new InMemory([
    1 => [
        'username' => 'john.doe',
        'password' => 'secret',
        'name'     => 'John Doe',
    ],
]);

$authenticator = new UserPassword(new Plaintext);
$session = new Native;

$auth = new SessionAuth($identifier, $authenticator, $session);

// returns true to indicate success
$auth->login([
    'username' => 'john.doe',
    'password' => 'secret',
]);

Later, when login succeeds, check for the current login:

// returns true/false
$auth->check();

// returns the current caller
$caller = $auth->getCurrentCaller();

And logout at the end:

// returns true/false
$auth->logout();

API Authentication

Since Guardian is an authentication library, you can easily use it to authenticate API requests without persistence. To achieve this, see the following simple authentication service:

use Indigo\Guardian\Identifier\InMemory;
use Indigo\Guardian\Authenticator\UserPassword;
use Indigo\Guardian\Hasher\Plaintext;
use Indigo\Guardian\RequestAuth;

$identifier = new InMemory([
    1 => [
        'username' => 'john.doe',
        'password' => 'secret',
        'name'     => 'John Doe',
    ],
]);

$authenticator = new UserPassword(new Plaintext);

$auth = new RequestAuth($identifier, $authenticator);

$subject = [
    'username' => 'john.doe',
    'password' => 'secret',
];

// returns true to indicate success
$auth->authenticate($subject);

// returns the caller object if identify succeeds
$caller = $auth->authenticateAndReturn($subject);

Testing

$ phpspec run

Contributing

Please see CONTRIBUTING for details.

Credits

License

The MIT License (MIT). Please see License File for more information.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-02-23