Download the PHP package okneloper/jwt-validators without Composer
On this page you can find all versions of the php package okneloper/jwt-validators. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download okneloper/jwt-validators
More information about okneloper/jwt-validators
Files in okneloper/jwt-validators
Package jwt-validators
Short Description JWT validation library for lcobucci/jwt v3
License MIT
Informations about the package jwt-validators
JWT validation library for lcobucci/jwt v3
Easily validate your lcobucci/jwt JWTs, add custom validators when you need. This package is intended for use with lcobucci/jwt v3. V4 will include validation improvements, so it might not require any additional packages to set up token validation.
Installation
composer require okneloper/jwt-validators
Validating tokens
Included Validators
ClaimPresenceValidator
Validates if a particular claim is present.
ExpirationValidator
Validates if exp claim is present and the token is not expired.
LifetimeValidator
Validates if token lifetime is less or equal to the number of seconds. Handy for validating tokens issued by other issuers.
SignaturePresenceValidator
Validates if the token is signed. This will prevent an exception when trying to verify signature on a token without one.
UniqueJtiValidator
Validates if the token does not exist in a custom storage. To use it, you
need to pass it an instance of a call implementing TokenExistenceChecker
interface. This is a simple interface that lets you define how to check if
the token exists on your records. Example usage:
Writing custom validators
There are 2 ways to write a custom validator depenfing on the complexity of you validator you require.
ITokenValidator interface
A token validator a class that implements ITokenValidator
interface.
This interface has 2 methods:
Simply implement this interface and you can add this validator to your list of validators.
TokenValidator class
To simplify the process of writing validators the library includes an abstract class that implements this interface and the Decorator pattern that lets you chain multiple validators. For instance you want check that a claim exists before you will validate the value. Splitting this logic into 2 separate validators allows for clean and exact error messages. This helps developers consuming your api a lot.
All you need to do is define your error message and the validation method: