Menu

Simple Authentication
Simple Authentication methods for faster development

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 = new Leaf\Core\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

$token = $authentication->generateSimpleToken(24', 'LEAF PHP SECRET CODE 1442');

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..... In v1.3, this method takes in 2 params, the entire payload of your JWT and a secret phrase. check out JWT for more info on JWT payload params.

  • (array) - JWT payload
  • (string) - A secret phrase to encode with the token

$token = $authentication->generateToken($payload, "secret phrase");

validateToken()

This method is used to confirm the identity of a token from an authorization header

$token = $authentication->validateToken();

getBearerToken()

This method is used to get the bearer token from an authorization header

$token = $authentication->getBearerToken();

getAuthorizationHeader()

This method is used to an authorization header

$authHeader = $authentication->getAuthorizationHeader();

Next Steps

Session
Simple Routing
Request
Response