Download the PHP package sprocketbox/laravel-jwt without Composer

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

Laravel JWT

Latest Stable Version Latest Unstable Version License Scrutinizer Code Quality

Laravel JWT provides a seamless JWT (JSON Web Tokens) implementation that integrates directly with Laravels authentication library allowing for stateless API authentication.

Table of Contents

Installing

To install this package simply run the following command.

This package uses auto-discovery to register the service provider but if you'd rather do it manually, the service provider is:

Configuring

There are no extra configuration files required, but there are a few extra options when configuring a guard in config/auth.php.

Here's an example configuration for a JWT guard.

Quick configuration

If you don't care to dive into all the extra bits you can create a very minimal JWT guard config by:

Driver

If you wish to use the JWT driver, just set the driver option to jwt.

Key

If you wish for your tokens to be signed you must, at the very least, provide a key using the key option. As the default signature uses a SHA256 HMAC, I recommend a 64 character key.

It's best you place this key in your env file as JWT_KEY or something similar.

Signer

By default this package will create a signature using a SHA256 HMAC, but if you wish to change that you can set the signer option to be the class name of a valid signer.

The default is Lcobucci\JWT\Signer\Hmac\Sha256 but there are other options in the Lcobucci\JWT\Signer namespace. If you wish to keep the default you can omit this option.

TTL

By default this package will set the TTL (total time to live) to 1 month, or more precisely P1M. If you wish to change this you can set the ttl config value to be a valid interval spec.

Custom generation

If you wish to generate the token yourself you can provide a custom generator like so:

The generator must return an instance of Lcobucci\JWT\Builder.

Custom validation

If you wish to provide custom validation for your token you may provide it like so:

If the validation fails you must return false. Any other return type, including null will be treated as a pass.

Custom token signature generation

In some situations you may find that the static signing method and key in the config isn't sufficient. If that is the case, you can provide an override like so:

This must return an array with two indexes, the first being the signer and the second being the key.

Generating keys

You can generate a key per guard by running the jwt:generate command with the name of the guard. The commands signature is:

Usage

This package functions in an almost identical way to Laravels session authentication, with a few exceptions.

Providing the token

The token is loaded as a bearer token, so you must provide it as a bearer token in the HTTP authorization header.

If you passed true as the second argument for attempt() the token will be automatically provided by the cookie, removing the need to manually pass the token.

Getting the token

The Auth::attempt($credentials) method is missing the second parameter (remember me) and instead of returning a boolean, returns an instance of Lcobucci\JWT\Token. Casting this object to a string will give you the actual JWT token.

If you wish to get the token currently being used, as in, the currently authenticated token, you can call the token() method on the guard, the same way you would call user()

Example

Take the following code as an example:

Avoiding XSS

If you pass true as the second argument for attempt() the guard will create a HTTP only (Not accessible via javascript) cookie. This will prevent you from having to store the token in the browsers localStorage.

To make sure that the cookie is added to the response you need to add the following middleware to your routes.

It makes sense to add this to the api group. Though it's not technically required, I recommend that you also add the following middleware to encrypt the cookies.

It's also advised to simply return a 204 response when using this method so that the token data isn't output anywhere.

Events

The login and authenticated events are called just like with the session guard.

The token

By default the token generation is somewhat opinionated, but that is because this is the initial version of this package.

The following covers how the claims are populated.

The token is generated using the lcobucci/jwt package.

The future

There are a couple of things that I wish to add into later versions of this package. I've made an attempt to list them all here, as a sort of roadmap.


All versions of laravel-jwt with dependencies

PHP Build Version
Package Version
Requires php Version ^7.3
lcobucci/jwt Version ^3.0
laravel/framework Version ^6.0 || ^7.0 || ^8.0
ramsey/uuid Version ^3.7
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 sprocketbox/laravel-jwt contains the following files

Loading the files please wait ....