conferenciacorp/autenticacao

此包最新版本(v1.4.2)没有提供许可证信息。

v1.4.2 2018-01-19 20:12 UTC

This package is auto-updated.

Last update: 2024-09-21 19:35:13 UTC


README

使用JWT进行身份验证的简单用户

安装

#!shell

composer require conferenciacorp/autenticacao

使用方法

<?php

use ConferenciaCorp\Autenticacao\Autenticacao;

//create the authentication
$autenticacao = new Autenticacao($secretKey);

//verify if the token is valid
if ($autenticacao->setToken($token)->isValid()) {

    //get user from the payload of the JWT
    $user = $autenticacao->getUser();

}

之后,您将获得一个来自 ConferenciaCorp\Autenticacao\User\User 的对象,并且可以检查权限

<?php

$aclAllowed = 'developer';

if ($user->can($aclAllowed)) {
    echo "Hey, {$user->getNome()}. You are an Developer!";
}

有效负载 - 最小要求

{
    "nome": "Marcelo Cerqueira",
    "acl": [
        "developer"
    ]
}

有效负载 - 额外数据

如果您想在有效负载中包含额外数据

{
    "nome": "Marcelo Cerqueira",
    "acl": [
        "developer"
    ],
    "data": [
        {
            "company": "ConferenciaCorp"
        }
    ]
}

然后在您的php中

$data = $user->getData();

echo "Amazing! You work at {$data['company']}!";

或者

echo "Amazing! You work at {$user->company}!";

鸣谢

感谢 Namshi/Jose PHP JWT库