8000 GitHub - gabrielfs7/jwt: A simple library to work with JSON Web Token and JSON Web Signature
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

gabrielfs7/jwt

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JWT

master Build Status develop Build Status

Total Downloads Latest Stable Version

A simple library to work with JSON Web Token and JSON Web Signature (requires PHP 5.5+)

Instalation

Just add to your composer.json: "lcobucci/jwt": "*"

Basic usage

Creating

Just use the builder to create a new JWT/JWS tokens:

<?php
use Lcobucci\JWT\Builder;
use Lcobucci\JWT\Signer\Sha256;

$token = (new Builder())->setIssuer('http://example.com') // Configures the issuer (iss claim)
                        ->setAudience('http://example.org') // Configures the audience (aud claim)
                        ->setId('4f1g23a12aa', true) // Configures the id (jti claim), replicating as a header item
                        ->set('uid', 1) // Configures a new claim, called "uid"
                        ->sign(new Sha256(), 'my key') // Signs the token with HS256 using "my key" as key
                        ->getToken(); // Retrieves the generated token
                        
echo $token; // The string representation of the object is a JWT string (pretty easy, right?)

Parsing from strings

Use the parser to create a new token from a JWT string:

<?php
use Lcobucci\JWT\Parser;

$token = (new Parser())->parse('...'); // Parses from a string
$token->getHeader(); // Retrieves the token header
$token->getClaims(); // Retrieves the token claims
$token->verify('my key'); // Verifies if the signature was created with given key (if token is signed)

About

A simple library to work with JSON Web Token and JSON Web Signature

Resources

License

Stars

Watchers

Forks

Packages

No packages published
0