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