attla/data-token

Turn everything into a token: randomized or predictable.

dev-main 2022-08-14 17:37 UTC

This package is auto-updated.

Last update: 2024-10-21 16:23:13 UTC


README

License Latest Stable Version Total Downloads

🪅 Turn everything into a token: randomized or predictable.

Installation

composer require attla/data-token

Usage

Creating and managing a token

use Attla\DataToken\Facade as DataToken;

// Create with facade
$token = DataToken::secrete('your secret phrase');

// Set the issuer claim
$token->iss();

// Set the expiration in minutes
$token->exp(120);

// Set payload of the token
$token->payload($model);

// Set the browser identifier on token
$token->bwr();

// Set user IP on the token
$token->ip();

// Get the token
$tokenEncoded = $token->encode();

Decoding the token

// Get token value as associative array
$tokenValue = DataToken::decode($tokenEncoded, true);

// Aliases for decode a token
$tokenValue = DataToken::fromString($tokenEncoded);
$tokenValue = DataToken::parseString($tokenEncoded);
$tokenValue = DataToken::parse($tokenEncoded);

Others ways to make a token

// Make a unique token from anything
$id = DataToken::id(123);

// Make always the same token
$sid = DataToken::sid(123);

// Make a strong token
$sign = DataToken::sign(123);

List of message methods

License

This package is licensed under the MIT license © Octha.