dilsonjlrjr/slim3-auth

1.1 2016-09-15 14:17 UTC

This package is not auto-updated.

Last update: 2024-09-14 19:53:01 UTC


README

模块 Auth Slim 3

安装

您可以直接从 composer / packagist 安装此库

$ composer require "dilsonjlrjr/slim3-auth"

依赖项

使用方法

slim3 -auth 在您的认证过程中使用三个组件

  • 适配器
  • 认证响应
  • 外观认证

适配器

适配器负责定义认证规则。每个适配器实现 AuthAdapterInterface 接口,并使用其构造函数作为输入。所有适配器都应该返回一个类型为 AuthResponse 的对象。以下是一个适配器实例。

use SlimAuth\AuthResponse;
use SlimAuth\AuthAdapterInterface;

class AuthTestAdapter implements AuthAdapterInterface
{

    private $username;

    private $password;

    /**
     * AuthTestAdapter constructor.
     * Data entry
     * @param string $username
     * @param string $password
     */
    public function __construct(string $username, string $password)
    {
        $this->username = $username;
        $this->password = $password;
    }

    function authenticate() : AuthResponse
    {
        if ($this->username == 'username' && $this->password == 'password') {
            return new AuthResponse(AuthResponse::AUTHRESPONSE_SUCCESS, 'User auth success', 'Slim3Auth', [ 'id' => 1010 ]);
        }

        return new AuthResponse(AuthResponse::AUTHRESPONSE_FAILURE, 'Failure');
    }

}
适配器 - 方法

authenticate

Define:
	Authenticates according to the rules defined in the implemented class
Params:
	no params;
Return:
	SlimAuth\AuthResponse

认证响应

AuthResponse 类表示认证过程的结果。它有定义状态的常量,AUTHRESPONSE_SUCCESS(认证成功),AUTHRESPONSE_FAILURE(认证失败)。

认证响应 - 方法

__construct

Define:
	Set message result autenticate
Params:
	$code [int] - AUTHRESPONSE_SUCCESS or AUTHRESPONSE_FAILURE;
	$message [string] - Defined user. Message result authentication;
	$keyAttributeSession [string] - Key used for session rescue;
	$attributesSession [array] - Array with attributes session;
Return:
	no returns;

setMessage

Define:
	Set message result autenticate
Params:
	$code [int] - AUTHRESPONSE_SUCCESS or AUTHRESPONSE_FAILURE;
	$message [string] - Defined user. Message result authentication;
	$keyAttributeSession [string] - Key used for session rescue;
	$attributesSession [array] - Array with attributes session;
Return:
	no returns;

getMessage

Define:
	Get array message
Params:
	no params;
Return:
	no returns;
Example:
	[
		$code, [int]
		$message, [string]
		$keyAttributeSession, [string]
		$attributesSession, [array]
	]

外观认证

此外观运行预先设置的适配器,并将其存储在由适配器设置的会话属性中。

外观认证 - 方法

__construct

Define:
	The class constructor
Params:
	$authAdapter [SlimAuth\AuthAdapterInterface] - implemented adapter interface SlimAuth\AuthAdapterInterface;
	$session [RKA\Session] - Stored Session

Return:
	no returns;

auth

Define:
	Auth method
Params:
	no params;
Return:
	no returns;

isValid

Define:
	It indicates whether the authentication was valid
Params:
	no params;
Return:
	boolean;

联系方式

Email: dilsonjlrjr@gmail.com