Update 'README.md'
Fixed code blocks
This commit is contained in:
parent
6b1d3178cf
commit
5a4a2845e4
11
README.md
11
README.md
@ -30,17 +30,18 @@ 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);
|
||||
@ -48,12 +49,13 @@ or a `JwtPlaintextKey` and pass it to the `JwtToken` constructor:
|
||||
$tok->claims->add("some/claim/MaxItems", 8);
|
||||
|
||||
$str = $tok->getSignedToken();
|
||||
|
||||
```
|
||||
|
||||
### Parsing tokens
|
||||
|
||||
Parsing is done by passing the raw token as the 2nd parameter
|
||||
|
||||
```php
|
||||
use NoccyLabs\SimpleJwt\JwtToken;
|
||||
|
||||
$str = "...received token...";
|
||||
@ -72,9 +74,11 @@ Parsing is done by passing the raw token as the 2nd parameter
|
||||
|
||||
// You can also use valueOf() to return a default value if needed
|
||||
$val = $tok->claims->valueOf("some/claim/MaxItems", 64);
|
||||
```
|
||||
|
||||
### Validating tokens
|
||||
|
||||
```php
|
||||
use NoccyLabs\SimpleJwt\Validator\JwtValidator;
|
||||
|
||||
$validator = new JwtValidator();
|
||||
@ -93,3 +97,4 @@ Parsing is done by passing the raw token as the 2nd parameter
|
||||
catch (JwtValidatorException $e) {
|
||||
// validation failed
|
||||
}
|
||||
```
|
Loading…
Reference in New Issue
Block a user