PHPackages                             gozoro/jwt - 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. gozoro/jwt

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

gozoro/jwt
==========

A simple PHP class to encode and decode JSON Web Tokens (JWT), conforming to RFC 7519.

v1.0.0(5y ago)09MITPHPPHP &gt;=5.5.9

Since Jul 9Pushed 5y ago1 watchersCompare

[ Source](https://github.com/gozoro/jwt)[ Packagist](https://packagist.org/packages/gozoro/jwt)[ Docs](https://github.com/gozoro/jwt)[ RSS](/packages/gozoro-jwt/feed)WikiDiscussions master Synced today

READMEChangelogDependenciesVersions (2)Used By (0)

JWT
===

[](#jwt)

A simple PHP class to encode and decode JSON Web Tokens (JWT), conforming to RFC 7519. Supported algorithms: HS256, HS512, HS384, RS256, RS384, RS512.

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

[](#installation)

```
	composer require gozoro/jwt

```

Usage
-----

[](#usage)

**Encode**

```
$key     = 'my_secret_key';
$tokenId = '12345';
$beginTs = time();
$endTs   = $beginTs + 3600;
$issuer  = 'oauth.example.com';
$subject = 'subject',
$audience= 'audience',

try
{
	$jwt = new \gozoro\jwt\JWT('HS256');
	$jwt->setTokenId($tokenId);
	$jwt->setNotBeforeTime($beginTs);
	$jwt->setExpirationTime($endTs);
	$jwt->setIssuedAtTime($beginTs);
	$jwt->setIssuer($issuer);
	$jwt->setSubject($subject);
	$jwt->setAudience(audience);

	print $jwtstr = \gozoro\jwt\JWT::encode($jwt, $key);
}
catch(\gozoro\jwt\JwtEncodeException $e)
{
	print $e->getMessage();
}
```

or

```
try
{
	$payload = [
		'jti' => $tokenId,
		'nbf' => $beginTs,
		'exp' => $endTs,
		'iat' => $beginTs,
		'iss' => $issuer,
		'sub' => $subject,
		'aud' => $audience,
	];

	$jwt = new \gozoro\jwt\JWT('HS256');
	$jwt->setPayload($payload);

	print $jwtstr = \gozoro\jwt\JWT::encode($jwt, $key);
}
catch(\gozoro\jwt\JwtEncodeException $e)
{
	print $e->getMessage();
}
```

**Decode**

```
try
{
	$jwt = \gozoro\jwt\JWT::decode($jwtstr);

	print $jwt->getTokenId();
	print $jwt->getNotBeforeTimeFormatted('Y-m-d H:i:s');
	print $jwt->getExpirationTimeFormatted('Y-m-d H:i:s');
	print $jwt->getIssuedAtTimeFormatted('Y-m-d H:i:s');
	print $jwt->getIssuer();
	print $jwt->getAudience();

	print_r($jwt->getHeader());
	print_r($jwt->getPayload());
	print $jwt->getSignature();
}
catch(\gozoro\jwt\JwtDecodeException $e)
{
	print $e->getMessage();
}
```

**Validate**

```
try
{
	$key    = 'my_secret_key';
	$leeway = 300;

	if($jwt->validateHeader())
		print 'Header: OK';

	if($jwt->validateSignature($key))
		print 'Signature: OK';

	if($jwt->validateNotBeforeTime($leeway))
		print 'Not Before Time: OK';

	if($jwt->validateExpirationTime($leeway))
		print 'Expiration Time: OK';

	if($jwt->validateTime($leeway)) // $jwt->validateNotBeforeTime($leeway) and $jwt->validateExpirationTime($leeway)
		print 'Time: OK';
}
catch(\gozoro\jwt\JwtValidateException $e)
{
	print $e->getMessage();
}
```

###  Health Score

22

—

LowBetter than 21% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

2184d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/a273abe77cdd4c74270a90320efbeb4d4dfb3ceac5b4d505ce2ccafddf1e06e0?d=identicon)[gozoro](/maintainers/gozoro)

---

Top Contributors

[![gozoro](https://avatars.githubusercontent.com/u/13768280?v=4)](https://github.com/gozoro "gozoro (18 commits)")

---

Tags

jwtRFC7519jsonwebtoken

### Embed Badge

![Health badge](/badges/gozoro-jwt/health.svg)

```
[![Health](https://phpackages.com/badges/gozoro-jwt/health.svg)](https://phpackages.com/packages/gozoro-jwt)
```

###  Alternatives

[web-token/jwt-framework

JSON Object Signing and Encryption library for PHP and Symfony Bundle.

95220.7M102](/packages/web-token-jwt-framework)[web-token/jwt-library

JWT library

2013.9M132](/packages/web-token-jwt-library)[web-token/jwt-bundle

JWT Bundle of the JWT Framework.

132.7M8](/packages/web-token-jwt-bundle)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
