2017 © Pedro Peláez
 

library jwx

A PHP library for JSON web tokens (JWT) with signature (JWS) and encryption (JWE) support.

image

sop/jwx

A PHP library for JSON web tokens (JWT) with signature (JWS) and encryption (JWE) support.

  • Tuesday, December 19, 2017
  • by sop
  • Repository
  • 1 Watchers
  • 5 Stars
  • 578 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 16 Versions
  • 7 % Grown

The README.md

JWX

Build Status Scrutinizer Code Quality Coverage Status License, (*1)

A PHP library for JSON web tokens (JWT) with signature (JWS) and encryption (JWE) support., (*2)

Also implements unencoded payload option (RFC 7797)., (*3)

Features

  • Signing and signature validation (JWS)
    • HMAC, RSA and EC
  • Encryption and decryption with compression and integrity protection (JWE)
    • AES
  • Claims validation
    • Configurable with sensible defaults
  • JSON Web Keys (JWK)
    • Convert PEM encoded keys to JWK and vice versa

Supported algorithms

  • Signature
    • HMAC with SHA-256, SHA-384 and SHA-512
    • RSASSA-PKCS1-v1_5 with SHA-256, SHA-384 and SHA-512
    • ECDSA with P-256, P-384 and P-521 curves
  • Content encryption
    • AES-CBC with 128, 192 and 256-bit key sizes
    • AES-GCM with 128, 192 and 256-bit key sizes
  • Key management
    • Shared symmetric key (direct)
    • RSAES-PKCS1-v1_5
    • RSAES OAEP
    • AES Key Wrap with 128, 192 and 256-bit key sizes
    • AES-GCM key encryption with 128, 192 and 256-bit key sizes
    • Password-based key encryption (PBES2 with AES Key Wrap)
  • Compression
    • DEFLATE

Requirements

Installation

This library is available on Packagist., (*4)

composer require sop/jwx

Usage

Claims class holds Claim objects that represent the claims. The claims shall be encoded into a JWT which may further be signed or encrypted, producing a JWS or a JWE respectively., (*5)

JWS and JWE may also be used to carry arbitrary payload, not just JSON claims., (*6)

Code examples

Simple JWT

Parse JWT from https://jwt.io/ HS512 example., (*7)

$jwt = new JWT($token);
// create context for the claims validation
// 'your-512-bit-secret' key is used to verify the signature
$ctx = ValidationContext::fromJWK(
    SymmetricKeyJWK::fromKey('your-512-bit-secret'));
// validate claims
$claims = $jwt->claims($ctx);
// print value of the subject claim
echo $claims->subject()->value();

Additional Validation

Parse the same token as above but additionally validate subject and admin claims., (*8)

$jwt = new JWT($token);
// validate that the subject is "1234567890"
// validate that the admin claim is true using explicitly provided validator
$ctx = ValidationContext::fromJWK(
    SymmetricKeyJWK::fromKey('your-512-bit-secret'),
        ['sub' => '1234567890']
    )->withConstraint('admin', true, new EqualsValidator());
// validate and print all claims
$claims = $jwt->claims($ctx);
foreach ($claims as $claim) {
    printf("%s: %s\n", $claim->name(), $claim->value());
}

More Examples

See /examples directory for more examples., (*9)

License

This project is licensed under the MIT License., (*10)

The Versions

19/12 2017

dev-master

9999999-dev https://github.com/sop/jwx

A PHP library for JSON web tokens (JWT) with signature (JWS) and encryption (JWE) support.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Joni Eskelinen

json jwt token jws json web token jwe jose json web signature jwk json web encryption json web key

19/12 2017

0.10.1

0.10.1.0 https://github.com/sop/jwx

A PHP library for JSON web tokens (JWT) with signature (JWS) and encryption (JWE) support.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Joni Eskelinen

json jwt token jws json web token jwe jose json web signature jwk json web encryption json web key

15/12 2017

0.10.0

0.10.0.0 https://github.com/sop/jwx

A PHP library for JSON web tokens (JWT) with signature (JWS) and encryption (JWE) support.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Joni Eskelinen

json jwt token jws json web token jwe jose json web signature jwk json web encryption json web key

02/08 2017

0.9.0

0.9.0.0 https://github.com/sop/jwx

A PHP library for JSON web tokens (JWT) with signature (JWS) and encryption (JWE) support.

  Sources   Download

MIT

The Requires

 

The Development Requires

  • ietf-jose/cookbook *

by Joni Eskelinen

json jwt token jws json web token jwe jose json web signature jwk json web encryption json web key

12/10 2016

0.8.0

0.8.0.0 https://github.com/sop/jwx

A PHP library for JSON web tokens (JWT) with signature (JWS) and encryption (JWE) support.

  Sources   Download

MIT

The Requires

 

The Development Requires

  • ietf-jose/cookbook *

by Joni Eskelinen

json jwt token jws json web token jwe jose json web signature jwk json web encryption json web key

21/06 2016

0.7.2

0.7.2.0 https://github.com/sop/jwx

A PHP library for JSON web tokens (JWT) with signature (JWS) and encryption (JWE) support.

  Sources   Download

MIT

The Requires

 

The Development Requires

  • ietf-jose/cookbook *

by Joni Eskelinen

json jwt token jws json web token jwe jose json web signature jwk json web encryption json web key

21/06 2016

0.7.1

0.7.1.0 https://github.com/sop/jwx

A PHP library for JSON web tokens (JWT) with signature (JWS) and encryption (JWE) support.

  Sources   Download

MIT

The Requires

 

The Development Requires

  • ietf-jose/cookbook *

by Joni Eskelinen

json jwt token jws json web token jwe jose json web signature jwk json web encryption json web key

17/06 2016

0.7.0

0.7.0.0 https://github.com/sop/jwx

A PHP library for JSON web tokens (JWT) with signature (JWS) and encryption (JWE) support.

  Sources   Download

MIT

The Requires

 

The Development Requires

  • ietf-jose/cookbook *

by Joni Eskelinen

json jwt token jws json web token jwe jose json web signature jwk json web encryption json web key

15/06 2016

0.6.0

0.6.0.0 https://github.com/sop/jwx

A PHP library for JSON web tokens (JWT) with signature (JWS) and encryption (JWE) support.

  Sources   Download

MIT

The Requires

 

The Development Requires

  • ietf-jose/cookbook *

by Joni Eskelinen

json jwt token jws json web token jwe jose json web signature jwk json web encryption json web key

14/06 2016

0.5.0

0.5.0.0 https://github.com/sop/jwx

A PHP library for JSON web tokens (JWT) with signature (JWS) and encryption (JWE) support.

  Sources   Download

MIT

The Requires

 

The Development Requires

  • ietf-jose/cookbook *

by Joni Eskelinen

json jwt token jws json web token jwe jose json web signature jwk json web encryption json web key

08/06 2016

0.4.0

0.4.0.0 https://github.com/sop/jwx

A PHP library for JSON web tokens (JWT) with signature (JWS) and encryption (JWE) support.

  Sources   Download

MIT

The Requires

 

The Development Requires

  • ietf-jose/cookbook *

by Joni Eskelinen

json jwt token jws json web token jwe jose json web signature jwk json web encryption json web key

31/05 2016

0.3.0

0.3.0.0 https://github.com/sop/jwx

A PHP library for JSON web tokens (JWT) with signature (JWS) and encryption (JWE) support.

  Sources   Download

MIT

The Requires

 

The Development Requires

  • ietf-jose/cookbook *

by Joni Eskelinen

json jwt token jws json web token jwe jose json web signature jwk json web encryption json web key

13/05 2016

0.2.1

0.2.1.0 https://github.com/sop/jwx

A PHP library for JSON web tokens (JWT) with signature (JWS) and encryption (JWE) support.

  Sources   Download

MIT

The Requires

 

The Development Requires

  • ietf-jose/cookbook *

by Joni Eskelinen

json jwt token jws json web token jwe jose json web signature jwk json web encryption json web key

09/05 2016

0.2.0

0.2.0.0 https://github.com/sop/jwx

A PHP library for JSON web tokens (JWT) with signature (JWS) and encryption (JWE) support.

  Sources   Download

MIT

The Requires

 

The Development Requires

  • ietf-jose/cookbook *

by Joni Eskelinen

json jwt token jws json web token jwe jose json web signature jwk json web encryption json web key

04/05 2016

0.1.1

0.1.1.0 https://github.com/sop/jwx

A PHP library for JSON web tokens (JWT) with signature (JWS) and encryption (JWE) support.

  Sources   Download

MIT

The Requires

 

The Development Requires

  • ietf-jose/cookbook *

by Joni Eskelinen

json jwt token jws json web token jwe jose json web signature jwk json web encryption json web key

04/05 2016

0.1.0

0.1.0.0 https://github.com/sop/jwx

A PHP library for JSON web tokens (JWT) with signature (JWS) and encryption (JWE) support.

  Sources   Download

MIT

The Requires

 

The Development Requires

  • ietf-jose/cookbook *

by Joni Eskelinen

json jwt token jws json web token jwe jose json web signature jwk json web encryption json web key