Overview
Leaf v1.4.2 has added a new method of token authentication to it's arsenal. Leaf token has a much simpler and cleaner syntax, also, it's very easy to work with, though it's not so secure at the moment.
Including Leaf Token
To include the Token object in a route, use this:
Leaf Token currently has security issues, therefore, it's not recommended for anything but personal projects
Unlike the tokens you're used to, Leaf token saves all data passed into it as an object which can be used later for authentication or something else.
Token Methods
generateSimpleToken
This method creates a simple base 64 token which contains JSON encoded data. It takes in 3 parameters, a username, a user id and an expiry time in seconds. The expiry time for the token is optional: if none is set, it sets the expiry time to 1 week.
This will encode the data passed into it and return it as the token value.
generateToken
As the name implies, generateToken also generates a base64 encoded token, the same as generateSimpleToken, but unlike generateSimpleToken, generateToken takes in 2 parameters: the token data to encode and the expiry time of the token. The expiry time for the token is optional: if none is set, it sets the expiry time to 1 week.
This will encode the data passed into it and return it as the token value.
validateToken
This is where Leaf Token gets interesting. Validate token just checks to see if the token is a valid leaf app token, also, it checks if the token is still active (not expired), from there, it just returns the token data. validateToken takes in just one parameter: the token returned from the user.
With Leaf Token, you can save data in your token and retrieve it after validating the token, quite handy๐๐
Next Steps
File SystemResponse
Simple Authentication
Database Config