Overview
Working with tokens
Leaf provides you with the $jwt object which includes various methods for creating and parsing token data....but we do not advice directly using the $jwt object. For this reason, a special $authentication object has been created to work with all the $jwt data. To use $authentication,
Authentication methods:
generateSimpleToken()
This method generates a new JSON Web Token. It takes 2 arguments. check out JWT for more info on JWT params
- (int) - A user id to encode
- (string) - A secret phrase to encode with the token
generateToken()
This method generates a new JSON Web Token: the same as generateSimpleToken()
, the only difference is that this method gives you more control over the token
i.e. expiry time..... It takes 4 parameters. check out JWT for more info on JWT params
- (int) - A user id to encode
- (int) - Expiry time....this is the amount of time the token will last from the current time
- (string) - A secret phrase to encode with the token
- (string) - iss - issuer....identifies the principal that issued the JWT - default is localhost
validateToken()
This method is used to confirm the identity of a token from an authorization header
getBearerToken()
This method is used to get the bearer token from an authorization header
getAuthorizationHeader()
This method is used to an authorization header
Next Steps
Re-routing to index.phpSimple Routing
Request
Response