Git Product home page Git Product logo

php-jwt's Introduction

Introduction

This project is forked from fkooman/php-jwt.

Then I changed the algorithm of EdDSA to Ed25519 in src\EdDSA.php file.

That's all.

The following is original readme.


This is small JSON Web Token implementation. It only supports signatures with the following signature algorithms:

  • HS256 (HMAC using SHA-256)
  • RS256 (RSASSA-PKCS1-v1_5 using SHA-256)
  • EdDSA (Ed25519, RFC 8037)

The first two seem to be the most widely deployed JWT signature algorithms. The library does NOT support encryption/decryption due to the can of worms that would open. It MAY support encryption/decryption in the future, but definitely not with RSA.

Which Algorithm to Use?

If you are both the signer and the verifier of the JWT use HS256. If you issue JWTs that have to be verified by third parties (as well), use EdDSA. Do NOT use RS256 if you can help it.

Why?

Quite a number of JWT implementations exist for PHP, varying in quality. However, JWT can be insecure, so it is very important to get things right and as simple as possible from a security perspective. This means implementing the absolute minimum to support JWT, in a secure way. Simplicity and security is more important than fully supporting every nook and cranny of the specification.

How?

  • Only supports RS256, HS256 and EdDSA through separate classes, the header is NOT used to determine the algorithm when verifying signatures;
  • All keys are validated before use and wrapped in "Key" objects to make sure they are of the correct format. Helper methods are provided to load / save / generate keys;
  • Does NOT support the crit header key. If a token is presented with the crit header key it will be rejected;
  • Verifies the exp and nbf payload field if present to make sure the token is already and still valid.

Versions

Version PHP OS
1.x >= 5.4 CentOS >= 7 (+EPEL), Debian >= 9
2.x >= 7.2 CentOS >= 8 (+EPEL), Debian >= 10

Requirements

  • PHP >= 7.2
  • php-hash (for HS256)
  • php-openssl (for RS256)
  • php-sodium (for EdDSA)

Only paragonie/constant_time_encoding is a dependency.

Installation

Currently php-jwt is not hosted on Packagist. It may be added in the future. In your composer.json:

"repositories": [
    {
        "type": "vcs",
        "url": "https://git.tuxed.net/fkooman/php-jwt"
    },
    ...
],

"require": {
    "fkooman/jwt": "^2",
    ...
},

You can also download the signed source code archive here.

API

See the example/ directory for working examples on how to generate keys, set the Key ID and create and validate JWT tokens.

Testing

You can run the included test suite after cloning the repository:

$ /path/to/composer install
$ vendor/bin/phpunit

Benchmark

You can use PHPBench to run some benchmarks comparing the various signature algorithms.

$ /path/to/phpbench run

php-jwt's People

Watchers

James Cloos avatar Hassan Kreiger 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.