Documentation

GenerateApiToken

Use case for generating API tokens for users.

Tokens are hashed before storage for security. Only the hash is stored in the database; the plaintext token is returned to the user and never stored. This protects tokens in case of database breach.

Tags
since
3.0.0

Table of Contents

Constants

API_TOKEN_EXPIRATION  = 30 * 24 * 60 * 60
API token expiration time in seconds (default: 30 days).

Properties

$repository  : UserRepositoryInterface
User repository.
$tokenHasher  : TokenHasher
Token hasher.

Methods

__construct()  : mixed
Create a new GenerateApiToken use case.
execute()  : string
Execute to generate an API token.

Constants

API_TOKEN_EXPIRATION

API token expiration time in seconds (default: 30 days).

private mixed API_TOKEN_EXPIRATION = 30 * 24 * 60 * 60

Properties

Methods

execute()

Execute to generate an API token.

public execute(int $userId) : string

Returns the plaintext token to the user but stores only the hash.

Parameters
$userId : int

The user ID

Tags
throws
InvalidArgumentException

If user not found

Return values
string

The generated API token (plaintext)


        
On this page

Search results