superbrave/auth0-http-client

Auth0 API client authentication for the Symfony HTTP client.

3.0.0 2024-03-08 10:35 UTC

README

Latest version on Packagist Software License Build Status Coverage Status Code Quality

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.