Giter Site home page Giter Site logo

jwt's Introduction

JWT

master Build Status Scrutinizer Code Quality Code Coverage

develop Build Status Scrutinizer Code Quality Code Coverage

Total Downloads Latest Stable Version

A simple library to work with JSON Web Token and JSON Web Signature (requires PHP 5.5+). The implementation is based on the current draft.

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\Hmac\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)

jwt's People

Contributors

lcobucci avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.