Download the PHP package stechstudio/laravel-jwt without Composer

On this page you can find all versions of the php package stechstudio/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 Tools

Latest Version on Packagist Build Status

This package wraps the excellent lcobucci/jwt library with the following benefits:

1) JWT facade with helper methods to quickly generate and parse tokens. 2) Enforces a minimal set of claims for generated tokens, like aud, iss, and exp. 3) Validate parsed tokens to ensure our required claims are set properly with signature present and valid. 4) HTTP Middleware to validate a route-specific JWT 5) Request macro to easily access route-specific JWT claims

Quickstart

Installation

Simple example

You can generate a simple JWT with the get method.

This will generate a token with the ID provided and an array of claims, returning the string token.

Lifetime

The default token expiration is set to 10 minutes which you can configure, or you can specify a custom lifetime value as a third parameter when creating the token:

This token will expire in one hour. You can also specify the lifetime with Carbon:

Signing key

If you are generating a JWT that will be consumed by a different app (very common use case in our company) you can specify the signing key as the fourth parameter.

Configuration

This package tries to pick sane defaults, while also allowing you to change configs through your .env file.

Signature key

Every token is signed. The JWT_SIGNING_KEY value is used is available, otherwise APP_KEY will be used as the signing key.

Lifetime

Default lifetime is 600 seconds / 10 minutes. You can change the default by specifying the number of seconds as JWT_LIFETIME.

Issuer

The default token issuer (iss claim) is your APP_NAME lowercase. You can specify a different issuer name via JWT_ISSUER.

Audience

The default token audience (aud claim) is your APP_NAME lowercase. You can specify a different audience name via JWT_AUDIENCE.

Building tokens fluently

So far we've looked at the JWT::get() helper method which is super quick for simple needs.

For more control over your token you can create it fluently instead.

You can use any of the methods provided by the underlying Builder class, along with a few new ones like signWith and lifetime.

Parsing

You can parse a JWT string into a token:

An exception will be thrown if the JWT cannot be parsed.

Validate received tokens

Just as this package has opinions on what a generated token should include, we want to ensure those minimums are set appropriately on any received tokens.

After parsing a received token, simply call isValid or validate, depending on whether you want a boolean result or exceptions thrown. Make sure to pass in the expected token ID.

At this point you can be certain that the token:

1) Is signed, and the signature is verified (using the configured signature key) 2) Is within the permitted timeframe (has not expired) 3) Is intended for your app (aud claim matches the configured audience) 4) Has the expected ID

Validation exceptions

When calling validate('expected-token-id') the following exceptions will be thrown depending on the validation failure:

Retrieving claims

Once you've parsed and validated a token, you can retrieve all token claims with getClaims or simply toArray.

If you'd like to just retrieve your custom payload claims, use getPayload;

Or to retrieve just one claim, use get passing in the name of the claim. You can optionally pass in a default value as the second parameter;

Route middleware

We frequently use JWTs to authorize a request. These are sometimes generated and consumed by the same app, but more frequently they are for cross-app authorization.

You can use the included jwt middleware to validate a JWT request. The middleware will look for the JWT in a number of places:

1) As a request parameter named jwt or token 2) As a route paramater named jwt or token 3) In the Authorization header either as Token JWT or Bearer :base64encodedJWT

If a token is found in any of these locations it will be parsed and validated.

Token ID

By default, the token ID will be expected to match the route name.

For example, with this following route the token will need an ID of my.home:

You can specify the required ID by passing it as a middleware parameter:

Access claims on request

All token claims

The Laravel Request has a getClaim macro on it, so you can grab claims from anywhere.

Example when injecting $request into a controller method:

Custom payload merged

The token payload (custom claims added to the JWT, not part of the core registered claim set) is merged onto the request attributes, so you can access these just like any other request attribute.

If the JWT has a foo claim, you can directly access $request->foo or $request->input('foo') or even request('foo') using the global request helper.

_Note: When the payload is merged onto the request, there is a chance that we are stomping on some existing request attributes. Because we really trust the payload in a validated JWT, we prefer this behavior. However if you want to disable set JWT_MERGE_PAYLOAD=false in your .env file._


All versions of laravel-jwt with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1
lcobucci/jwt Version ^4.3
illuminate/support Version ^8.0|^9.0|^10.0|^11.0
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 stechstudio/laravel-jwt contains the following files

Loading the files please wait ....