superbrave / auth0-http-client
Auth0 API client authentication for the Symfony HTTP client.
Requires
- php: ^8.2
- symfony/cache: ^6.4|^7.0
- symfony/http-client-contracts: ^3.4
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.45
- phpunit/phpunit: ^10.0
- symfony/http-client: ^6.4|^7.0
Suggests
- symfony/http-client: This package requires an actual Symfony HTTP client implementation to decorate.
Provides
This package is auto-updated.
Last update: 2024-11-08 11:59:42 UTC
README
Auth0 API client authentication for the Symfony HTTP client.
Installation using Composer
Run the following command to add the package to the composer.json of your project:
$ composer require superbrave/auth0-http-client symfony/http-client
The symfony/http-client
can be replaced with any other HTTP client implementing the Symfony HTTP client contracts.
Usage
The following example shows how to create the instances required to do an API call authenticated through Auth0:
<?php use Superbrave\AuthZeroHttpClient\AuthZeroAuthenticatingHttpClient; use Superbrave\AuthZeroHttpClient\AuthZeroConfiguration; use Symfony\Component\HttpClient\HttpClient; $httpClient = HttpClient::create(); $authZeroConfiguration = new AuthZeroConfiguration( 'https://dev-1234.eu.auth0.com', // Your Auth0 tenant URL 'clientId', // Your application's Client ID 'clientSecret', // Your application's Client Secret 'https://www.superbrave.nl/api' // The unique identifier of the target API you want to access ); $authZeroHttpClient = new AuthZeroAuthenticatingHttpClient($httpClient, $authZeroConfiguration); $response = $authZeroHttpClient->request('GET', 'https://superbrave.nl/api');
Optionally, a custom cache instance can be injected into the AuthZeroAuthenticatingHttpClient
. The cache will store
the access tokens (JWT) for the configured TTL returned by Auth0.
License
The Auth0 HTTP client is licensed under the MIT License. Please see the LICENSE file for details.