PHPackages                             remessage/json-web-token - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. remessage/json-web-token

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

remessage/json-web-token
========================

A JSON Web Token (RFC 7519) implementation library

v0.7.1(2y ago)055—0%Apache-2.0PHPPHP &gt;=8.3

Since Jan 24Pushed 2y ago1 watchersCompare

[ Source](https://github.com/re-message/json-web-token)[ Packagist](https://packagist.org/packages/remessage/json-web-token)[ Docs](https://dev.remessage.ru/packages/json-web-token)[ RSS](/packages/remessage-json-web-token/feed)WikiDiscussions release Synced today

READMEChangelogDependencies (20)Versions (32)Used By (0)

Json Web Token Implementation
=============================

[](#json-web-token-implementation)

[![Version](https://camo.githubusercontent.com/2895c255bb04fcdb71ad30c977c3fac7c5fca223e97946394028e4fb9bd93ea1/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f72656d6573736167652f6a736f6e2d7765622d746f6b656e3f7374796c653d666f722d7468652d6261646765)](https://camo.githubusercontent.com/2895c255bb04fcdb71ad30c977c3fac7c5fca223e97946394028e4fb9bd93ea1/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f72656d6573736167652f6a736f6e2d7765622d746f6b656e3f7374796c653d666f722d7468652d6261646765)[![PHP Version Support](https://camo.githubusercontent.com/9c0e9ef4cfae55b11da763b86c63335dc92807900d3ed1245eccbc93b30a6513/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f72656d6573736167652f6a736f6e2d7765622d746f6b656e3f7374796c653d666f722d7468652d6261646765)](https://camo.githubusercontent.com/9c0e9ef4cfae55b11da763b86c63335dc92807900d3ed1245eccbc93b30a6513/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f72656d6573736167652f6a736f6e2d7765622d746f6b656e3f7374796c653d666f722d7468652d6261646765)[![License](https://camo.githubusercontent.com/a25a15f856f89098cce42b2ff9547eb27a9cc052867adfa22bdabddf383fd694/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f72652d6d6573736167652f6a736f6e2d7765622d746f6b656e3f7374796c653d666f722d7468652d6261646765)](https://camo.githubusercontent.com/a25a15f856f89098cce42b2ff9547eb27a9cc052867adfa22bdabddf383fd694/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f72652d6d6573736167652f6a736f6e2d7765622d746f6b656e3f7374796c653d666f722d7468652d6261646765)[![GitHub Workflow Status](https://camo.githubusercontent.com/6c952985da244fd8e01857b6eff768523424627651750fcdfdcfb9a62899ca41/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f72652d6d6573736167652f6a736f6e2d7765622d746f6b656e2f74657374696e672e79616d6c3f7374796c653d666f722d7468652d6261646765)](https://camo.githubusercontent.com/6c952985da244fd8e01857b6eff768523424627651750fcdfdcfb9a62899ca41/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f72652d6d6573736167652f6a736f6e2d7765622d746f6b656e2f74657374696e672e79616d6c3f7374796c653d666f722d7468652d6261646765)

This library implements a series of standards related with JSON Web Token and is used by others [Re: Message](https://remessage.ru) libraries and services like `remessage/client` and API server.

Installation
------------

[](#installation)

You will need Composer to install. Run this command:

`composer require remessage/json-web-token`

Usage
-----

[](#usage)

### Algorithms

[](#algorithms)

All tokens and services uses algorithms to sign, verify, encrypt and decrypt the token data. Each algorithm MUST implement `RM\Standard\Jwt\Algorithm\AlgorithmInterface`.

At this moment, we provide only HMAC-based algorithms:

1. `RM\Standard\Jwt\Algorithm\Signature\HMAC\HS256` for HMAC with SHA-256
2. `RM\Standard\Jwt\Algorithm\Signature\HMAC\HS512` for HMAC with SHA-512
3. `RM\Standard\Jwt\Algorithm\Signature\HMAC\HS3256` for HMAC with SHA3-256 (or Keccak256)
4. `RM\Standard\Jwt\Algorithm\Signature\HMAC\HS3512` for HMAC with SHA3-512 (or Keccak512)

Also, you can implement your own algorithm. You need implement the `RM\Standard\Jwt\Algorithm\AlgorithmInterface` interface.

### Keys

[](#keys)

Each key must implement the `RM\Standard\Jwt\Key\Factory\KeyInterface` interface.

At the moment, we provide support for:

1. Octet key
2. RSA keys (PSS and PKCS1) *(only signing)*

Also, you can implement your own key. You need implement the `RM\Standard\Jwt\Key\Factory\KeyFactoryInterface` interface to create your key from array. If your key contains a property that is not implemented in this library, then you also need to implement the `RM\Standard\Jwt\Key\Parameter\KeyParameterInterface` interface and use `RM\Standard\Jwt\Key\Parameter\Factory\ParameterFactory` with your key parameter class.

### Tokens

[](#tokens)

To create new token you can use the `RM\Standard\Jwt\Signature\SignatureToken` class. The class constructor have 3 arguments: header parameters, payload claims and signature. The header parameters must include the algorithm parameter. Other arguments is optional.

Example:

```
