conferenciacorp/autenticacao

There is no license information available for the latest version (v1.4.2) of this package.

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

This package is auto-updated.

Last update: 2024-04-21 18:41:59 UTC


README

A Simple User with authentication with JWT

Installation

#!shell

composer require conferenciacorp/autenticacao

Usage

<?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();

}

After that you have an object from ConferenciaCorp\Autenticacao\User\User and you can check even permissions

<?php

$aclAllowed = 'developer';

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

Payload - minimum requirements

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

Payload - additional data

if you want extra data on your payload:

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

And in your php

$data = $user->getData();

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

Or

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

Credits

Thanks to Namshi/Jose PHP JWT Library