free2er / jwt
JWT tools
1.0.0
2020-03-17 15:21 UTC
Requires
- php: ^7.4
- ext-gmp: *
- ext-json: *
- ext-openssl: *
- ext-sodium: *
- free2er/ed25519: ^1.0
- nesbot/carbon: ^2.31
- web-token/jwt-checker: ^2.1
- web-token/jwt-core: ^2.1
- web-token/jwt-key-mgmt: ^2.1
- web-token/jwt-signature: ^2.1
- web-token/jwt-signature-algorithm-ecdsa: ^2.1
- web-token/jwt-signature-algorithm-eddsa: ^2.1
- web-token/jwt-signature-algorithm-hmac: ^2.1
- web-token/jwt-signature-algorithm-none: ^2.1
- web-token/jwt-signature-algorithm-rsa: ^2.1
Requires (Dev)
- free2er/coding-standard: ^1.1
- phpunit/phpunit: ^8.5
This package is auto-updated.
Last update: 2024-11-18 01:40:02 UTC
README
JWT tools
Installation
This component can be installed with the Composer dependency manager.
-
Install the component as a dependency of your project
composer require free2er/jwt
Usage
Create JWK
use Free2er\Jwt\KeyFactory; $factory = new KeyFactory(); $factory->create('/path/to/private.key'); $factory->create('/path/to/public.key');
Create JWT
use Free2er\Jwt\TokenFactory; $factory = new TokenFactory(); $factory->create(['aud' => 'client', 'sub' => 'user'], '/path/to/private.key');
Validate JWT
use Free2er\Jwt\TokenValidator; $validator = new TokenValidator(); $validator->validate('some.jwt.token', '/path/to/public.key');
OpenSSL commands
Generate RSA keys
openssl genrsa -out private.key 2048 openssl rsa -in private.key -pubout -out public.key
Generate RSA keys with password
openssl genrsa -passout pass:_passphrase_ -out private.key 2048 openssl rsa -in private.key -passin pass:_passphrase_ -pubout -out public.key
Generate EC P-256 keys
openssl ecparam -name prime256v1 -genkey -noout -out private.key openssl ec -in private.key -pubout -out public.key
Generate EC P-384 keys
openssl ecparam -name secp384r1 -genkey -noout -out private.key openssl ec -in private.key -pubout -out public.key
Generate EC P-521 keys
openssl ecparam -name secp521r1 -genkey -noout -out private.key openssl ec -in private.key -pubout -out public.key
Generate Ed25519 keys
openssl genpkey -algorithm Ed25519 -out private.key openssl pkey -in private.key -pubout -out public.key