Download the PHP package consilience/laravel-api-token-generator without Composer

On this page you can find all versions of the php package consilience/laravel-api-token-generator. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-api-token-generator

laravel-api-token-generator

Laravel supports API token authentication out of the box. When developing, and for internal (machine-to-machine) APIs, it is useful to be able to generate tokens for a user. This package provides a simple Artisan command to generate a token.

The token will be hashed using the sha256 algorithm.

This package does not provide a database migration for the api_token column. That is left to your application.

Installation

Installing with composer:

composer require consilience/laravel-api-token-generator

Lumen

For Laravel, the service provider and configuration file are registered automatically. With Lumen, additional entried are needed in bootstrap/app.php.

The service provider is registered:

$app->register(Consilience\Laravel\ApiTokenGenerator\Providers\ServiceProvider::class);

If the configuration file is published, add:

$app->configure('apitokens');

then copy apitokens.php:

cp vender/consilience/laravel-api-token-generator/apitokens.php config/apitokens.php

Publishing assets:

php artisan vendor:publish --provider="Consilience\ApiTokenGenerator\ApiTokenGeneratorServiceProvider"

Configuration

You can change the model that will hold the API tokens. By default this will be App\User, but yu may want App\Models\User for example.

'model' => App\Models\User::class,

The name_field is an alternative column to id that can be used to uniquely identify a model instance:

'name_field' => 'name'

The token column will be api_token by default, but can be changed:

'token_field' => 'my_api_token_column',

Note: this package does not add the API token column to your users table. That is a step for other packages or your application deployment.

Usage

Generate a new token or replace the existing token for a user:

php artisan apitoken:generate --id=123 --generate
php artisan apitoken:generate --id=5fd40c23-fcda-4bdc-a07c-f2bfeb56bb03 --generate

The id is normally an integer, but some this should also work if the id is a string such as UUID.

A generated token will only be displayed once. It is encrypted for saving against the model, so cannot be recovered if not recorded immediately.

Where users are uniquely identified by another column, then that column can be used to identify the model instance to update with a new token:

php artisan apitoken:generate [email protected] --generate

Rather than generating a random token, you can set your own explicit tokanes. Use the --token= option to do this instead of the --generate option.

php artisan apitoken:generate --id=123 --token=d8a928b2043db77e340b523547bf16cb4aa483f0645fe0a290ed1f20aab76257

If using for automated deployment, you may want to use the --no-ansi option to remove control characters.

The --check option will tell you whether an instance has a token set or not:


All versions of laravel-api-token-generator with dependencies

PHP Build Version
Package Version
No informations.
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package consilience/laravel-api-token-generator contains the following files

Loading the files please wait ....