2017 © Pedro Peláez
 

library jose

JSON Object Signing and Encryption library for PHP.

image

namshi/jose

JSON Object Signing and Encryption library for PHP.

  • Tuesday, May 1, 2018
  • by odino
  • Repository
  • 39 Watchers
  • 707 Stars
  • 6,296,750 Installations
  • PHP
  • 59 Dependents
  • 0 Suggesters
  • 73 Forks
  • 12 Open issues
  • 67 Versions
  • 11 % Grown

The README.md

NAMSHI | JOSE

Deprecation notice

Hi there,, (*1)

as much as we'd like to be able to work on all of the OSS in the world, we don't actively use this library anymore This means that new features / bugfixes / etc will only be merged based on pull requests from external contributors, and we strongly recommend you look for a long-term alternative., (*2)

If you're looking for an actively maintained library check firebase/php-jwt out!, (*3)

Build Status Latest Stable Version Total Downloads License, (*4)

This library provides a lightweight implementation of the JWS (JSON Web Signature) specification., (*5)

Prerequisites

This library needs PHP 5.5+ and the library OpenSSL., (*6)

It has been tested using PHP5.5 to PHP7.0 and HHVM., (*7)

Installation

You can install the library directly from composer / packagist:, (*8)

"namshi/jose": "7.0.*"

Usage

Using it is pretty straightforward: imagine that you want to offer a service the ability to authenticate a user via a cookie, and the service is built with javascript; what you would need to do is to generate a JWS (after verifying the credentials once), store it as a cookie and then pass it from your JavaScript app everytime you want to authenticate that user., (*9)

First, generate the JWS:, (*10)

``` php <?php, (*11)

use Namshi\JOSE\SimpleJWS;, (*12)

if ($username == 'correctUsername' && $pass == 'ok') { $user = Db::loadUserByUsername($username);, (*13)

$jws  = new SimpleJWS(array(
    'alg' => 'RS256'
));
$jws->setPayload(array(
    'uid' => $user->getid(),
));

$privateKey = openssl_pkey_get_private("file://path/to/private.key", self::SSL_KEY_PASSPHRASE);
$jws->sign($privateKey);
setcookie('identity', $jws->getTokenString());

}, (*14)


Then your JS app can use the available cookie to execute authenticated calls, without sending passwords or credentials. Once a request is submitted, you only have to verify that it is a valid call: ``` php <?php use Namshi\JOSE\SimpleJWS; $jws = SimpleJWS::load($_COOKIE['identity']); $public_key = openssl_pkey_get_public("/path/to/public.key"); // verify that the token is valid and had the same values // you emitted before while setting it as a cookie if ($jws->isValid($public_key, 'RS256')) { $payload = $jws->getPayload(); echo sprintf("Hey, my JS app just did an action authenticated as user #%s", $payload['uid']); }

PROTIP: you can omit the second argument of the isValid() method, so jose will try to validate the token with the algorithm specified in the token's header, though this might expose you to some security issues., (*15)

For now we recommend to always explicitely set the algorithm you want to use to validate tokens., (*16)

PHPSECLIB For RSA Verification

You may find that you need to use this library in an environment where PHP's wrappers for OpenSSL do not work, or OpenSSL simply is not installed. This library uses OpenSSL to encrypt by default, but you can specify that you want to use PHPSecLib for a pure PHP implementation of RSA encryption., (*17)

In these cases, simply add the optional 'SecLib' parameter when constructing a JWS:, (*18)

$jws = new JWS(array('alg' => 'RS256'), 'SecLib');

You can now use the PHPSecLib implementation of RSA signing. If you use a password protected private key, you can still submit the private key to use for signing as a string, as long as you pass the password as the second parameter into the sign method:, (*19)

$jws->sign(file_get_contents(SSL_KEYS_PATH . "private.key"), 'tests');

You may also load a JWS using the PHPSecLib implementation of RSA verification:, (*20)

$jws = JWS::load($tokenString, false, $encoder, 'SecLib');

Under the hood

In order to validate the JWS, the signature is first verified with a public key and then we will check whether the token is expired., (*21)

To give a JWS a TTL, just use the standard exp value in the payload:, (*22)

``` php $date = new DateTime('tomorrow'); $this->jws = new SimpleJWS(array('alg' => 'RS256')); $this->jws->setPayload(array( 'exp' => $date->format('U'), ));, (*23)


### Unsecure JWSes You can allow [unsecure JWSes](https://tools.ietf.org/html/draft-ietf-jose-json-web-algorithms-40#page-12) by setting the `$allowUnsecure` flag while loading JWSes: ``` php JWS::load($this->jws->getTokenString(), true);

This allows tokens signed with the 'none' algorithms to go through, which is something you probably don't want to do. Proceed with caution :), (*24)

Unsecure JWSes are disabled by default since version 2.2.2. You should **not use previous versions other than 2.2.2 as they have a security vulnerability. More info here.**, (*25)

Using a custom encoder

If, for some reason, you need to encode the token in a different way, you can inject any implementation of Namshi\JOSE\Base64\Encoder in a JWS instance. Likewise, JWS::load() accepts such an implementation as a second argument., (*26)

Implementation Specifics

The library provides a base JWT Class that implements what is needed just for JSON Web Tokens. The JWS Class then extends the JWT class and adds the implementation for signing and verifying using JSON Web Signatures. The SimpleJWS class extends the base JWS class and adds validation of a TTL and inclusion of automatic claims., (*27)

Major Versions

2.x.x to 3.x.x

Introduced the ability to specify an encryption engine. Added support of PHPSecLib to the existing OpenSSL implementation., (*28)

3.x.x to 4.x.x - Not Backwards Compatible

Added the ability to set custom properties in the header. Moved automatic inclusion of certain claims into an SimpleJWS class from the base JWS class., (*29)

6.x.x - Not Backwards Compatible

6.1.x

  • Dropped support for PHP 5.4
  • phpseclib 2.0

6.0.x

  • Dropped support for PHP 5.3
  • Don't escape slashes when generating signin input. This may render tokens generated with earlier versions of Jose incompatible.

7.x.x

7.0.x

Moved phpseclib and the openssl extension as suggested dependencies., (*30)

Tests

Tests are written using PHPUnit for this library. After doing composer install you can execute the following command to run tests:, (*31)

./vendor/bin/phpunit

Credits

This library has been inspired by the initial work done by @ritou., (*32)

The Versions

01/05 2018

dev-master

9999999-dev

JSON Object Signing and Encryption library for PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Alessandro Cinelli (cirpo)

json jwt token jws json web token json web signature

05/12 2016

7.2.3

7.2.3.0

JSON Object Signing and Encryption library for PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Alessandro Cinelli (cirpo)

json jwt token jws json web token json web signature

05/10 2016

7.2.2

7.2.2.0

JSON Object Signing and Encryption library for PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Alessandro Cinelli (cirpo)

json jwt token jws json web token json web signature

13/07 2016

7.2.1

7.2.1.0

JSON Object Signing and Encryption library for PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Alessandro Cinelli (cirpo)

json jwt token jws json web token json web signature

09/07 2016

7.2.0

7.2.0.0

JSON Object Signing and Encryption library for PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Alessandro Cinelli (cirpo)

json jwt token jws json web token json web signature

11/04 2016

7.1.0

7.1.0.0

JSON Object Signing and Encryption library for PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Alessandro Cinelli (cirpo)

json jwt token jws json web token json web signature

30/03 2016

7.0.0

7.0.0.0

JSON Object Signing and Encryption library for PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Alessandro Cinelli (cirpo)

json jwt token jws json web token json web signature

24/01 2016

6.1.1

6.1.1.0

JSON Object Signing and Encryption library for PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Alessandro Cinelli (cirpo)

json jwt token jws json web token json web signature

24/01 2016

dev-r611

dev-r611

JSON Object Signing and Encryption library for PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Alessandro Cinelli (cirpo)

json jwt token jws json web token json web signature

24/01 2016

dev-r605

dev-r605

JSON Object Signing and Encryption library for PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

json jwt token jws json web token json web signature

24/01 2016

dev-fix-mbstrlen

dev-fix-mbstrlen

JSON Object Signing and Encryption library for PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Alessandro Cinelli (cirpo)

json jwt token jws json web token json web signature

13/01 2016

6.1.0

6.1.0.0

JSON Object Signing and Encryption library for PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Alessandro Cinelli (cirpo)

json jwt token jws json web token json web signature

12/01 2016

dev-phpseclib-2

dev-phpseclib-2

JSON Object Signing and Encryption library for PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

json jwt token jws json web token json web signature

12/01 2016

dev-phpseclib2

dev-phpseclib2

JSON Object Signing and Encryption library for PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

json jwt token jws json web token json web signature

10/01 2016

dev-r6.0.4

dev-r6.0.4

JSON Object Signing and Encryption library for PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

json jwt token jws json web token json web signature

10/01 2016

6.0.4

6.0.4.0

JSON Object Signing and Encryption library for PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

json jwt token jws json web token json web signature

17/12 2015

dev-fix-ian-int-casting

dev-fix-ian-int-casting

JSON Object Signing and Encryption library for PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

json jwt token jws json web token json web signature

13/12 2015

dev-t6.0.4

dev-t6.0.4

JSON Object Signing and Encryption library for PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

json jwt token jws json web token json web signature

10/12 2015

dev-mbstring.func_overload-fix

dev-mbstring.func_overload-fix

JSON Object Signing and Encryption library for PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

json jwt token jws json web token json web signature

10/12 2015

dev-iat-should-be-int

dev-iat-should-be-int

JSON Object Signing and Encryption library for PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

json jwt token jws json web token json web signature

13/11 2015

6.0.3

6.0.3.0

JSON Object Signing and Encryption library for PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

json jwt token jws json web token json web signature

13/11 2015

dev-PHP7-test

dev-PHP7-test

JSON Object Signing and Encryption library for PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

json jwt token jws json web token json web signature

07/11 2015

dev-fix-hhvm-JWSTest

dev-fix-hhvm-JWSTest

JSON Object Signing and Encryption library for PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

json jwt token jws json web token json web signature

07/11 2015

dev-phpseclib-1.0.0

dev-phpseclib-1.0.0

JSON Object Signing and Encryption library for PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

json jwt token jws json web token json web signature

07/11 2015

dev-PHP7-support

dev-PHP7-support

JSON Object Signing and Encryption library for PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

json jwt token jws json web token json web signature

19/10 2015

6.0.2

6.0.2.0

JSON Object Signing and Encryption library for PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

json jwt token jws json web token json web signature

01/10 2015

6.0.1

6.0.1.0

JSON Object Signing and Encryption library for PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

json jwt token jws json web token json web signature

29/07 2015

6.0.0

6.0.0.0

JSON Object Signing and Encryption library for PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

json jwt token jws json web token json web signature

08/07 2015

dev-badge-poser

dev-badge-poser

JSON Object Signing and Encryption library for PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

json jwt token jws json web token json web signature

29/06 2015

5.0.2

5.0.2.0

JSON Object Signing and Encryption library for PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

json jwt token jws json web token json web signature

16/06 2015

2.2.2

2.2.2.0

JSON Object Signing and Encryption library for PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

json jwt token jws json web token json web signature

16/06 2015

3.0.1

3.0.1.0

JSON Object Signing and Encryption library for PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

json jwt token jws json web token json web signature

16/06 2015

4.0.1

4.0.1.0

JSON Object Signing and Encryption library for PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

json jwt token jws json web token json web signature

16/06 2015

dev-none-lower

dev-none-lower

JSON Object Signing and Encryption library for PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

json jwt token jws json web token json web signature

16/06 2015

5.0.1

5.0.1.0

JSON Object Signing and Encryption library for PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

json jwt token jws json web token json web signature

26/05 2015

5.0.0

5.0.0.0

JSON Object Signing and Encryption library for PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

json jwt token jws json web token json web signature

25/04 2015

4.0.0

4.0.0.0

JSON Object Signing and Encryption library for PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

json jwt token jws json web token json web signature

21/04 2015

3.0.0

3.0.0.0

JSON Object Signing and Encryption library for PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

json jwt token jws json web token json web signature

13/04 2015

2.2.1

2.2.1.0

JSON Object Signing and Encryption library for PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

json jwt token jws json web token json web signature

10/03 2015

2.2.0

2.2.0.0

JSON Object Signing and Encryption library for PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

json jwt token jws json web token json web signature

10/03 2015

2.1.4

2.1.4.0

JSON Object Signing and Encryption library for PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

json jwt token jws json web token json web signature

10/03 2015

dev-test-false-public-key

dev-test-false-public-key

JSON Object Signing and Encryption library for PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

json jwt token jws json web token json web signature

19/02 2015

2.1.3

2.1.3.0

JSON Object Signing and Encryption library for PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

json jwt token jws json web token json web signature

18/02 2015

dev-disabling-none-by-default

dev-disabling-none-by-default

JSON Object Signing and Encryption library for PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

json jwt token jws json web token json web signature

18/02 2015

dev-fix-hmac-timing-attacks

dev-fix-hmac-timing-attacks

JSON Object Signing and Encryption library for PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

json jwt token jws json web token json web signature

17/02 2015

2.1.2

2.1.2.0

JSON Object Signing and Encryption library for PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

json jwt token jws json web token json web signature

17/02 2015

2.0.3

2.0.3.0

JSON Object Signing and Encryption library for PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

json jwt token jws json web token json web signature

17/02 2015

1.2.2

1.2.2.0

JSON Object Signing and Encryption library for PHP.

  Sources   Download

MIT

The Requires

  • php >=5.3.3
  • lib-openssl *

 

The Development Requires

json jwt token jws json web token json web signature

17/02 2015

dev-fix-1

dev-fix-1

JSON Object Signing and Encryption library for PHP.

  Sources   Download

MIT

The Requires

  • php >=5.3.3
  • lib-openssl *

 

The Development Requires

17/02 2015

1.1.2

1.1.2.0

JSON Object Signing and Encryption library for PHP.

  Sources   Download

MIT

The Requires

  • php >=5.3.3
  • lib-openssl *

 

The Development Requires

17/02 2015

dev-fixing-bypassing-auth

dev-fixing-bypassing-auth

JSON Object Signing and Encryption library for PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

json jwt token jws json web token json web signature

14/01 2015

2.1.0

2.1.0.0

JSON Object Signing and Encryption library for PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

json jwt token jws json web token json web signature

29/12 2014

2.0.2

2.0.2.0

JSON Object Signing and Encryption library for PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

json jwt token jws json web token json web signature

29/12 2014

2.1.1

2.1.1.0

JSON Object Signing and Encryption library for PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

json jwt token jws json web token json web signature

27/12 2014

2.0.1

2.0.1.0

JSON Object Signing and Encryption library for PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

json jwt token jws json web token json web signature

16/12 2014

2.0.0

2.0.0.0

JSON Object Signing and Encryption library for PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

json jwt token jws json web token json web signature

27/09 2014

1.2.1

1.2.1.0

JSON Object Signing and Encryption library for PHP.

  Sources   Download

MIT

The Requires

  • php >=5.3.3
  • lib-openssl *

 

The Development Requires

json jwt token jws json web token json web signature

05/09 2014

dev-readme-fix

dev-readme-fix

JSON Object Signing and Encryption library for PHP.

  Sources   Download

MIT

The Requires

  • php >=5.3.3
  • lib-openssl *

 

The Development Requires

json jwt token jws json web token json web signature

17/07 2014

1.2.0

1.2.0.0

JSON Object Signing and Encryption library for PHP.

  Sources   Download

MIT

The Requires

  • php >=5.3.3
  • lib-openssl *

 

The Development Requires

16/07 2014

1.1.1

1.1.1.0

JSON Object Signing and Encryption library for PHP.

  Sources   Download

MIT

The Requires

  • php >=5.3.3
  • lib-openssl *

 

The Development Requires

16/06 2014

1.1.0

1.1.0.0

JSON Object Signing and Encryption library for PHP.

  Sources   Download

MIT

The Requires

  • php >=5.3.3
  • lib-openssl *

 

The Development Requires

09/01 2014

dev-php5.5-essential

dev-php5.5-essential

JSON Object Signing and Encryption library for PHP.

  Sources   Download

MIT

The Development Requires

19/09 2013

1.0.2

1.0.2.0

JSON Object Signing and Encryption library for PHP.

  Sources   Download

MIT

The Development Requires

19/09 2013

1.0.1

1.0.1.0

JSON Object Signing and Encryption library for PHP.

  Sources   Download

MIT

The Development Requires

13/07 2013

1.0.0

1.0.0.0

JSON Object Signing and Encryption library for PHP.

  Sources   Download

MIT

The Development Requires

13/07 2013

1.0.0-rc1

1.0.0.0-RC1

JSON Object Signing and Encryption library for PHP.

  Sources   Download

MIT

The Development Requires

03/06 2013

1.0.0-beta1

1.0.0.0-beta1

JSON Object Signing and Encryption library for PHP.

  Sources   Download

MIT

The Development Requires