Fixed readme

This commit is contained in:
Chris 2023-04-09 02:46:48 +02:00
parent fabf160346
commit b9c690cb6e
1 changed files with 33 additions and 28 deletions

View File

@ -30,17 +30,19 @@ Install using composer:
You need a key for both generating and parsing tokens. Create a `JWTDerivedKey`
or a `JWTPlaintextKey` and pass it to the `JWTToken` constructor:
```php
use NoccyLabs\SimpleJWT\Key\{JWTDerivedKey,JWTPlaintextKey}
// Derive a key using secret and salt...
$key = new JWTDerivedKey("secret", "salt");
// ...or use a prepared plaintext key
$key = new JWTPlaintextKey("This Should Be Binary Data..");
```
### Generating tokens
```php
use NoccyLabs\SimpleJWT\JWTToken;
$tok = new JWTToken($key);
@ -54,6 +56,7 @@ $str = $tok->getSignedToken();
Parsing is done by passing the raw token as the 2nd parameter
```php
use NoccyLabs\SimpleJWT\JWTToken;
$str = "...received token...";
@ -76,6 +79,7 @@ $val = $tok->claims->valueOf("some/claim/MaxItems", 64);
### Validating tokens
```php
use NoccyLabs\SimpleJWT\Validator\JWTValidator;
$validator = new JWTValidator();
@ -94,3 +98,4 @@ $val = $tok->claims->valueOf("some/claim/MaxItems", 64);
catch (JWTValidatorException $e) {
// validation failed
}
```