fgsl / jwt
Fgsl JWT Handler
Installs: 151
Dependents: 3
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 0
Open Issues: 0
Type:component
pkg:composer/fgsl/jwt
Requires
- php: >=7.4
Requires (Dev)
- phpunit/phpunit: ^9.5
This package is auto-updated.
Last update: 2025-10-22 12:54:39 UTC
README
For creating a JWT token, you must before create an instance of Fgsl\Jwt\Jwt. After, you call method getBearerToken. This method will store the username in the token as the sub attribute. Additional attributes can be sent in an array as the third argument.
For recovering the payload from a given token, call the static method getPayload.
You can see a use example below. You can run this test from JwtTest class using PHPUnit.
public function testBearerToken() { $jwt = new Jwt(['RS256','sha256'], 'JWT', 'newbraveworld.com', 'PT2H'); $bearerToken = $jwt->getBearerToken('foouser','baapassword',['role' => 'admin']); $this->assertTrue(is_string($bearerToken)); $this->assertNotEmpty($bearerToken); $payload = Jwt::getPayload($bearerToken); $this->assertTrue(is_object($payload)); $this->assertEquals('foouser', $payload->sub); $this->assertEquals('newbraveworld.com', $payload->iss); $this->assertEquals('admin',$payload->role); $this->assertFalse(Jwt::expired($bearerToken)); }