Skip to content
martingallinelliPublic

About

Using Jason Web Token in native PHP

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Latest commit

 

History

7 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JWT

Aplicación de JWT en PHP nativo.



INSTALACION



Ejecutar el siguiente comando dentro de la carpeta del proyecto:

composer require firebase/php-jwt



CONFIGURACION TOKEN



  • Fecha y hora actual en segundos
    $time = time();
  • Fecha y hora de expiracion del token (+1 hora)
    $expires = $time + (60 * 60);
  • Llave privada
    $key = 'key_private';
  • Token
    $token = array(
        // fecha de creación
        'iat' => $time,
        // fecha de expiración
        'exp' => $expires,
        // informacion que guarda 
        $data = array(
            'id' => 1,
            'name' => 'Martin'
        )
    );


CODIFICAR TOKEN



JWT::encode(datosAguardar, secretKey)

    $jwt = JWT::encode($token, $key);


DECODIFICAR TOKEN



JWT::decode(tokenCodificado, secretKey, algoritmoCodificacion)

    $jwt = JWT::decode($jwt, $key, array('HS256'));

About

Using Jason Web Token in native PHP

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages