Download the PHP package bluemill/jwt-artisan without Composer

On this page you can find all versions of the php package bluemill/jwt-artisan. 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 jwt-artisan

JWT Artisan

Note: forked from https://github.com/generationtux/jwt-artisan and updated to work with Laravel >= 6 and PHP >= 7.2

Token auth for Laravel and Lumen web artisans

JWT is a great solution for authenticating API requests between various services. This package makes working with JWT super easy for both Laravel and Lumen.

Why JWT?

Because you have

microservices

That need to authenticate with each other so you can turn away bad requests like

how bout no

Which is why JWT makes you feel like

yea baby

Contents

Setup

Install the package using composer

$ composer require generationtux/jwt-artisan

Add the appropriate service provider for Laravel/Lumen

Configure

All configuration for this package can be set using environment variables. The reason for using environment variables instead of config files is so that it can be integrated with both Laravel & Lumen as easily as possible. See the table below for the available config options and their defaults.

Config Default Description
JWT_SECRET null The secret key that will be used for sigining/validating tokens.
JWT_ALGO HS256 The algorithm to use for sigining tokens.
JWT_LEEWAY 0 Seconds of leeway for validating timestamps to account for time differences between systems
JWT_INPUT token By default we will look for the token in the Authorization header. If it's not found there, then this value will be used to search the sent input from the request to find the token.
JWT_HEADER Authorization By default the Authorization header key is used. This can be overridden with this value.

If you're using the JwtExceptionHandler to handle exceptions, these environment variables can be set to customize the error messages. (see below for information on using the exception handler)

Config Default Description
JWT_MESSAGE_ERROR There was an error while validating the authorization token. 500 A general error occured while working with the token.
JWT_MESSAGE_INVALID Authorization token is not valid. 401 The provided token is invalid in some way: expired, mismatched signature, etc.
JWT_MESSAGE_NOTOKEN Authorization token is required. 401 There was no token found with the request.
JWT_MESSAGE_NOSECRET No JWT secret defined. 500 Unable to find the JWT secret for validating/signing tokens.

Working with Tokens

Creating Tokens

Inject an instance of GenTux\Jwt\JwtToken into your controller or other service to create new tokens.

Implement GenTux\Jwt\JwtPayloadInterface to pass other objects to createToken for a more dynamic payload.

Then simply pass that object when creating the token

You can set a specific secret and algorithm to use if necessary

Validating Tokens

The easiest way to validate a request with a JWT token is to use the provided middleware.

When a token is invalid, GenTux\Jwt\Exceptions\InvalidTokenException will be thrown. If no token is provided, then GenTux\Jwt\Exceptions\NoTokenException will be thrown.

To manually validate the token, you can get tokens in any class using the trait GenTux\Jwt\GetsJwtToken.

For example, in a Laravel request object

Or in a controller for Lumen

Payloads

Once you have the token, working with the payload is easy.

The payload method for JwtToken accepts a path that can be used to get specific data from the payload.

Handling Errors

This package can handle JWT exceptions out of the box if you would like. It will take all JWT exceptions and return JSON error responses. If you would like to implements your own error handling, you can look at GenTux\Jwt\Exceptions\JwtExceptionHandler for an example.

To implement, add the following inside of app/Exceptions/Handler.php


All versions of jwt-artisan with dependencies

PHP Build Version
Package Version
Requires firebase/php-jwt Version ^3.0
illuminate/http Version ^5.1
illuminate/support Version ^5.1
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 bluemill/jwt-artisan contains the following files

Loading the files please wait ....