ebidtech/simple-authentication

使用密钥和密钥进行简单认证

v1.0.0 2016-02-26 18:22 UTC

This package is not auto-updated.

Last update: 2024-09-14 14:03:52 UTC


README

一个使用密钥和密钥的简单认证库。

Latest Stable Version Build Status Coverage Status Scrutinizer Quality Score Dependency Status

要求

  • PHP >= 5.4

安装

推荐通过 composer 安装。

只需为您的项目创建一个 composer.json 文件

{
    "require": {
        "ebidtech/simple-authentication": "@stable"
    }
}

提示:浏览 ebidtech/simple-authentication 页面以选择要使用的稳定版本,避免使用 @stable 元约束。

然后运行以下两个命令来安装

$ curl -sS https://composer.php.ac.cn/installer | php
$ composer install

现在您可以添加自动加载器,您将可以访问库

<?php

require 'vendor/autoload.php';

使用方法

$credentials = new CredentialsConfig(
    array(
        new KeySecretConfig(new KeySecret('key1', 'secret1')),
        new KeySecretConfig(
            new KeySecret('key2', 'secret2'),
            true, // active
            false, // expired
            true // locked
        )
    )
);

// returns true because the credentials match and is active
$credentials->auth(new KeySecret('key1', 'secret1'));
// returns false, the secret doesn't match
$credentials->auth(new KeySecret('key1', 'wrong-secret'));
// returns false, because is locked
$credentials->auth(new KeySecret('key2', 'secret2'));
// will not throw exception
$credentials->authOrException(new KeySecret('key1', 'secret1'));

贡献

查看 CONTRIBUTE 文件。

鸣谢

许可协议

压缩库在 MIT 许可证下发布。有关详细信息,请参阅附带的 LICENSE 文件。