lcobucci/jwt: A PHP Library for JWT and JWS That Stays Close to RFC 7519
A simple library to work with JSON Web Token and JSON Web Signature.
At a glance
- What is it?
- lcobucci/jwt is a PHP library for creating and validating JSON Web Tokens and JSON Web Signatures. It targets developers who need RFC 7519 compliance without extra framework baggage, but its documentation is sparse.
- Who is it for?
- Adopt lcobucci/jwt if you need a PHP library that implements JWT and JWS per RFC 7519 with a minimal API and BSD-3-Clause licensing. It suits projects that already use Composer and want a lightweight dependency.
- Can I use it commercially?
- Yes. BSD-3-Clause is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
- Is it still maintained?
- Yes. The repository last received commits 3 days ago.
- What is it written in?
- Mainly PHP, according to GitHub's language statistics.
Answers come from the project's GitHub data, last synced on September 14, 2026, and from our analysis. They are not legal advice.
DEEP OPEN-SOURCE ANALYSIS
What lcobucci/jwt Solves for PHP Developers
The project is maintained, with the last push on October 17, 2025, and recent releases including 5.6.0 on the same date. The default branch is 6.0.x, which suggests active development toward a new major version. The README does not describe the API in detail, so you must consult the external documentation. That is a limitation for quick adoption, but the library's focus on RFC 7519 gives you a clear standard to verify against.
How the Library Works: Token Creation and Validation
The library likely uses the standard JWT claims such as 'iss', 'sub', 'exp', and 'aud' for validation. Since it is based on RFC 7519, you can expect it to support common signing algorithms like HS256, RS256, and ES256, though the README does not list them. The key point is that the library does not reinvent the token format; it implements the spec. That is both a strength and a constraint. It means interoperability with other JWT implementations, but it also means you must follow the RFC's rules, such as base64url encoding and JSON serialization. If you need non-standard claims or custom header parameters, you may have to work around the library's structure.
Getting Started: Installation and Basic Configuration
Installation is straightforward via Composer. The README gives a single command: 'composer require lcobucci/jwt'. This is the only concrete setup step mentioned. There is no mention of a configuration file or environment variables, which suggests that the library is used directly in code rather than through a service provider. After installation, you would typically create a key object, instantiate a token builder, and sign the token. The README does not show these steps, so you must refer to the documentation. The lack of a quick-start example in the README is a notable gap for a library that claims simplicity. However, the installation command is clear, and the package is available on Packagist, so the dependency management is standard. The library has a stable version 5.6.0 and a pre-release 6.0.x branch, which means you should specify a version constraint in your composer.json to avoid unexpected breaking changes. For example, you might use '^5.6' for stability, but the README does not advise on this.
Licence and Maintenance Considerations
The library is licensed under BSD-3-Clause, which is permissive and allows commercial use, modification, and redistribution with attribution. This is a low-license-risk dependency for most projects. The project is actively maintained, with a recent release in October 2025, so you can expect bug fixes and security updates. The default branch is 6.0.x, indicating that a new major version is in the works. Major version changes in a library like this can introduce breaking API changes, especially if the token handling internals are refactored. The maintenance cost is moderate: you need to track releases and test your code against new versions. The documentation is hosted on ReadTheDocs, but the README does not specify the exact documentation version for the stable release. The homepage points to the 'stable' version, while the README links to 'latest', which could be a different version. This discrepancy is a minor issue but something to verify when reading the docs.
Limitations and When This Library Is the Wrong Choice
The most obvious limitation is the lack of detailed documentation in the README. The README is minimal, with only installation instructions and links. If you are a developer who prefers to learn from the README, you will need to visit the external documentation, which may or may not be complete. Another limitation is that the library does not provide built-in key management. You must handle private and public keys yourself, which is typical for JWT libraries but still a responsibility. If you need to support token revocation, you will have to implement it on top of this library, as JWT is stateless by design. The library is also not a good fit for projects that require a full authentication stack, such as login endpoints, user sessions, or role-based access control. For those, you would need a framework like Symfony or Laravel with its security bundle. Finally, the default branch 6.0.x suggests that the 5.x series is legacy, so if you adopt the stable 5.6.0, you may eventually face a migration. If you need cutting-edge features, you might need to use the 6.0.x branch, which is not yet stable and may have unresolved issues.
Alternatives and How They Differ
A common alternative is firebase/php-jwt, which is another PHP library for JWT. The key difference is that firebase/php-jwt is a single-file library with a simpler API, while lcobucci/jwt is more feature-rich and follows the RFC more strictly. firebase/php-jwt focuses on simplicity and has a smaller codebase, making it easier to audit. However, it may not support all JWT features, such as nested tokens or complex validation. Another alternative is the LexikJWTAuthenticationBundle for Symfony, which integrates JWT with Symfony's security system. That bundle provides authentication listeners, user providers, and token storage, which lcobucci/jwt does not. If you are using Symfony, the bundle is a more complete solution. The choice depends on your framework and your need for control. lcobucci/jwt gives you more granular control over the token lifecycle, while the alternatives trade that for convenience. The README does not mention any alternatives, so this comparison is based on general knowledge of the PHP ecosystem, not on the project's own claims.
Editorial conclusion
Adopt lcobucci/jwt if you need a PHP library that implements JWT and JWS per RFC 7519 with a minimal API and BSD-3-Clause licensing. It suits projects that already use Composer and want a lightweight dependency. Skip it if you require extensive documentation, built-in key management, or if your team prefers a framework-integrated solution. Before adopting, verify the exact version you install, since the default branch is 6.0.x but the latest release is 5.6.0, and test token creation and validation against your specific algorithms and claims. Also confirm that the ReadTheDocs documentation at the stable link matches the version you use, as the README points to 'latest' while the homepage points to 'stable'.
Community notes