Download the PHP package deatil/php-jwt without Composer

On this page you can find all versions of the php package deatil/php-jwt. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package php-jwt

PHP-JWT

A JWT (JSON Web Token) library for php.

Dependencies

What the heck is a JWT?

JWT.io has a great introduction to JSON Web Tokens.

In short, it's a signed JSON object that does something useful (for example, authentication). It's commonly used for Bearer tokens in Oauth 2. A token is made of three parts, separated by .'s. The first two parts are JSON objects, that have been base64url encoded. The last part is the signature, encoded the same way.

The first part is called the header. It contains the necessary information for verifying the last part, the signature. For example, which encryption method was used for signing and what key was used.

The part in the middle is the interesting bit. It's called the Claims and contains the actual stuff you care about. Refer to RFC 7519 for information about reserved keys and the proper way to add your own.

What's in the box?

This library supports the parsing and verification as well as the generation and signing of JWTs. Current supported signing algorithms are HMAC SHA, RSA, RSA-PSS, and ECDSA, though hooks are present for adding your own.

Installation

you can install it using Composer.

Get Starting

use DateTimeImmutable;
use Deatil\JWT\Facade;
use Deatil\JWT\Signer\Hmac\HS256;
use Deatil\JWT\Key\InMemory;

$signer = new HS256();
$key    = InMemory::base64Encoded('FkL2+V+1k2auI3xxTz/2skChDQVVjT9PW1/grXafg3M=');

$t      = new DateTimeImmutable();
$claims = [
    "iss" => "joe",
    "exp" => $t->setTimestamp(1300819380),
    "http://example.com/is_root" => true,
];

$token = Facade::sign($signer, $claims, $key);
$tokenStr = $token->toString();

// ouput:
// make token: eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJqb2UiLCJleHAiOjEzMDA4MTkzODAsImh0dHA6Ly9leGFtcGxlLmNvbS9pc19yb290Ijp0cnVlfQ.CjlHUxjA0Z78-klPuDgGNjbK29ZiEIEh-D4Gnm5JkQ4
echo "make token: {$tokenStr} \n";

$token = Facade::parse($signer, $tokenStr, $key);
$iss = $token->claims()->get('iss');

// ouput:
// token iss: joe
echo "token iss: {$iss} \n";

Token Validator

use DateTimeImmutable;
use Deatil\JWT\Validator;
use Deatil\JWT\ValidationData;

$now = new DateTimeImmutable();

$data = new ValidationData(); // It will use the current time to validate (iat, nbf and exp)
$data->issuedBy('http://example.com');
$data->permittedFor('http://example.org');
$data->identifiedBy('4f1g23a12aa');

$validation = new Validator();

var_dump($validation->validate($token, $data)); // false, because token cannot be used before now() + 60

$data->currentTime($now->modify('+61 seconds')); // changing the validation time to future

var_dump($validation->validate($token, $data)); // true, because current time is between "nbf" and "exp" claims

$data->currentTime($now->modify('+4000 seconds')); // changing the validation time to future

var_dump($validation->validate($token, $data)); // false, because token is expired since current time is greater than exp

// We can also use the $leeway parameter to deal with clock skew (see notes below)
// If token's claimed now is invalid but the difference between that and the validation time is less than $leeway, 
// then token is still considered valid
$dataWithLeeway = new ValidationData($now, 20); 
$dataWithLeeway->issuedBy('http://example.com');
$dataWithLeeway->permittedFor('http://example.org');
$dataWithLeeway->identifiedBy('4f1g23a12aa');

var_dump($validation->validate($token, $dataWithLeeway)); // false, because token can't be used before now() + 60, not within leeway

$dataWithLeeway->currentTime($now->modify('+51 seconds')); // changing the validation time to future

var_dump($validation->validate($token, $dataWithLeeway)); // true, because current time plus leeway is between "nbf" and "exp" claims

$dataWithLeeway->currentTime($now->modify('+3610 seconds')); // changing the validation time to future but within leeway

var_dump($validation->validate($token, $dataWithLeeway)); // true, because current time - 20 seconds leeway is less than exp

$dataWithLeeway->currentTime($now->modify('+4000 seconds')); // changing the validation time to future outside of leeway

var_dump($validation->validate($token, $dataWithLeeway)); // false, because token is expired since current time is greater than exp

Signers

The JWT library have signers:

Sign PublicKey

ECDSA PublicKey:

use Deatil\JWT\Key\InMemory;

// from key pem
$prikey = InMemory::plainText("-----BEGIN PRIVATE KEY-----
...
-----END PRIVATE KEY-----");
$pubkey = InMemory::plainText("-----BEGIN PUBLIC KEY-----
...
-----END PUBLIC KEY-----");

// from key pem file, if have pass and $pass need set
$prikey = InMemory::file(__DIR__ . '/_keys/ecdsa/private.key', $pass);
$pubkey = InMemory::file(__DIR__ . '/_keys/ecdsa/pubkey.key');

EdDSA PublicKey:

use Deatil\JWT\Key\InMemory;

// from key bytes
$prikey = InMemory::base64Encoded("...");
$pubkey = InMemory::base64Encoded("...");

RSA PublicKey:

use Deatil\JWT\Key\InMemory;

// from key pem string with pkcs1 key
$prikey = InMemory::plainText("-----BEGIN RSA PRIVATE KEY-----
...
-----END RSA PRIVATE KEY-----");
$pubkey = InMemory::plainText("-----BEGIN RSA PUBLIC KEY-----
...
-----END RSA PUBLIC KEY-----");

// from key pem file, if have pass and $pass need set
$prikey = InMemory::file(__DIR__ . '/_keys/rsa/private.key', $pass);
$pubkey = InMemory::file(__DIR__ . '/_keys/rsa/pubkey.key');

LICENSE

Copyright


All versions of php-jwt with dependencies

PHP Build Version
Package Version
Requires php Version >=8.2
ext-hash Version *
ext-json Version *
ext-openssl Version *
ext-mbstring Version *
ext-sodium Version *
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package deatil/php-jwt contains the following files

Loading the files please wait ...