Download the PHP package marketredesign/mrd-auth0-laravel without Composer
On this page you can find all versions of the php package marketredesign/mrd-auth0-laravel. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package mrd-auth0-laravel
MRD Auth0 Laravel
Wrapper to easily configure Auth0 with a Laravel application.
Also includes a logger for NewRelic.
Getting Started
Prerequisites
- PHP 7.4 or higher
- PHP JSON extension
- PHP mbstring extension
- PHP XML extension
- PHP Curl extension
- Laravel 6 or higher
Installing
You can install the package via composer:
For configuration, the default config files can be published using the following command.
Select the option for Marketredesign\MrdAuth0Laravel\MrdAuth0LaravelServiceProvider
. This creates the config file
config/mrd-auth0.php
.
Upgrade to v2
See the UPGRADE guide for instructions when updating an application that uses v1 to v2.
Usage
See laravel-auth0 for instructions on how to configure authentication / authorization of users.
Authorizing dataset access
Add the dataset.access
middleware to the API route. Then, make sure the dataset ID is specified using either
dataset_id
or datasetId
. It can be part of the route itself or part of the request data (query param,
request body, etc.)
Requesting machine-to-machine tokens from Auth0
Use Auth0
facade. Can be used to retrieve a machine-to-machine token, only when running in console (e.g. from async
job). The tokens are automatically cached for half their expiration time.
When testing a function that retrieves a m2m token, execute Auth0::fake()
to use a mocked Auth0Repository which does
not make any API calls to Auth0. The fake repository can be influenced using the Auth0::fake...()
functions.
User repository
Use Users
facade. Can be used to retrieve a single user, or multiple users, by ID.
Also includes functionality to retrieve multiple users by email addresses.
When testing a function that uses the UserRepository (or Facade), execute Users::fake()
to use a mocked UserRepository
which does not make any API calls to Auth0. The fake repository can be influenced using Users::fake...()
methods.
Dataset repository
Use Datasets
facade. Can be used to retrieve authorized datasets for the current user making the API request.
When testing a function that uses the DatasetRepository (or Datasets facade), execute Datasets::fake()
to use a mocked
version of the DatasetRepository that does not make any API calls to the underlying user tool API. The fake repository
can be influenced using the Datasets::fake...()
methods.
Logging to NewRelic
Create a new logger in the config/logging.php
file (example code below) and make sure that the NEWRELIC_LICENSE_KEY
is set. Then, this logger can be selected as any other logger, for example by setting the LOG_CHANNEL
to 'newrelic'
.
This logger looks for optional app.repository
and app.version
config values to log along with every
logged message, so add those fields to the config/app.php
file if you want this to be included.
Example code
Logger for in `config/logging.php`: Optional `app.repository` and `app.version` config values for in `config/app.php`:Running the tests
Simply run:
Authors
- Marijn van der Horst - Initial work
See also the list of contributors who participated in this project.
License
The MIT License (MIT). Please see License File for more information.
All versions of mrd-auth0-laravel with dependencies
ext-json Version *
auth0/auth0-php Version ^8.3
auth0/login Version ~7.7.0
guzzlehttp/guzzle Version ^6.0|^7.0
illuminate/contracts Version ^6.0|^7.0|^8.0|^9.0
illuminate/support Version ^6.0|^7.0|^8.0|^9.0
newrelic/monolog-enricher Version ^2.0