Download the PHP package jorgemudry/laravel-remote-token-auth without Composer

On this page you can find all versions of the php package jorgemudry/laravel-remote-token-auth. 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-remote-token-auth

Laravel Remote Token Auth

Build Status Total Downloads Latest Stable Version License Stars

This package provides a hassle-free way to incorporate authentication in your application when token validation happens in an external service.

It registers a stateless auth guard (rta) that validates the request's bearer token against an external API and builds the authenticated user from the response, so only valid users gain access to your endpoints.

Every step of the process is replaceable, so you can adapt the package to whatever your validation service looks like.

Requirements

Installation

You can install the package via composer:

The package will automatically register its service provider.

Set the validation endpoint in your .env file:

Optionally, publish the config file to customize the rest:

Usage

To require authentication for a route, add the auth middleware with the rta guard:

On every request the package will:

  1. Extract the bearer token from the Authorization header.
  2. Send it (as a bearer token, in a GET request) to the configured endpoint.
  3. Extract the user attributes from the JSON response, using the configured response.user_path.
  4. Build the authenticated user, using the configured response.user_class.

Error handling

Failures are split into two groups, so clients can tell them apart:

Configuration

Caching validations

By default every authenticated request triggers one HTTP call to the validation service. If that becomes a problem (latency, rate limits), enable the cache:

Successful validations are cached (keyed by a SHA-256 hash of the token, in the configured cache.store) for cache.ttl seconds. A response is only cached after the whole pipeline accepts it (attributes resolved, user built), so failed or malformed validations are never cached. If the cache store itself fails or is misconfigured, the package reports the error and falls back to validating directly against the service — a cache outage never rejects valid tokens.

Trade-off: a token revoked in the external service keeps working in your application until the TTL expires. Keep the TTL short.

Advanced Usage

Replacing a single step of the pipeline

Each step is a small class bound to a contract from JorgeMudry\LaravelRemoteTokenAuth\Contracts:

Config key Contract Default behavior
token-resolver ResolvesToken Reads the bearer token from the request
token-validator ValidatesToken GETs the endpoint with the token, returns the JSON body
attributes-resolver ResolvesAttributes Extracts the attributes at response.user_path
user-maker CreatesUser Instantiates response.user_class with the attributes

To replace a step, implement the matching contract and point the config key to your class. For example, a validator that POSTs the token instead:

Your class is resolved through the container, so you can inject any dependency in its constructor. If you instead extend one of the default actions and keep its constructor, the standard configuration (endpoint, timeouts, user_path, user_class) is passed to your subclass automatically.

Signaling errors from a custom validator: throw ValidationServiceUnavailableException when the service is unreachable or failing (renders as 503, clients keep their tokens) and Illuminate\Auth\AuthenticationException when the token was rejected (renders as 401). If you use Laravel's HTTP client or Guzzle, their connection exceptions — and any error response whose status is not in http.rejection_statuses — are mapped to the 503 path automatically.

Using your own authenticated user class

Your class must implement Illuminate\Contracts\Auth\Authenticatable and accept the attributes array as its only constructor argument. The easiest way is extending the package's AuthenticatedUser (or Laravel's GenericUser):

Replacing the whole adapter

If you need full control, implement AdapterInterface and rebind it in a service provider:

Testing

To run the package's test suite, run the following command:

Upgrading from 0.x

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

If you would like to contribute to the package, please see CONTRIBUTING for information on how to get started.

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.


All versions of laravel-remote-token-auth with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1
guzzlehttp/guzzle Version ^7.8
illuminate/auth Version ^10.0|^11.0|^12.0
illuminate/contracts Version ^10.0|^11.0|^12.0
illuminate/http Version ^10.0|^11.0|^12.0
illuminate/support Version ^10.0|^11.0|^12.0
symfony/http-kernel Version ^6.2|^7.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 jorgemudry/laravel-remote-token-auth contains the following files

Loading the files please wait ...