PHP code example of pkit / auth

1. Go to this page and download the library: Download pkit/auth library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

pkit / auth example snippets


  
   // .../index.php
  on;
  /***/
  # pode ser configurado pelo .env 'SESSION_EXPIRES' e 'SESSION_PATH' respectivamente
  Session::config(
    /*tempo em segundos*/, 
    /*caminho para a sessão(opcional)*/
  );//opcional
  /***
  

  use Pkit\Auth\Session;
  /***/
  Session::login(/*payload: array*/);
  /***/
  $logged = Session::logged(); //: bool
  /***/
  $login = Session::getPayload(); //: bool
  /***/
  Session::logout()//: bool
  

  use Pkit\Auth\Jwt;

  # pode ser configurado pelo .env 'JWT_KEY', 'JWT_EXPIRES' e 'JWT_ALG' respectivamente
  Jwt::config(
    /*chave para criptografia*/, 
    /*tempo de expiração em segundos #opcional*/, 
    /*algoritmo de criptografia*/
  );
  

  $token = Jwt::tokenize(/*payload:array*/)//:string;
  /***/
  $valid = Jwt::validate(/*token:string*/);//:boolean
  /***/
  $payload = Jwt::getPayload(/*token:string*/)//:object
  /***/
  $tokenBearer = Jwt::createBearer(/*token:string*/)//:string Authorization
  /***/
  $token = Jwt::parseBearer(/*authorization:string*/)//:string;