superbrave/auth0-http-client

This package is not installable via Composer 1.x, please make sure you upgrade to Composer 2+. Read more about our Composer 1.x deprecation policy.

Auth0 API client authentication for the Symfony HTTP client.

1.2.1 2020-12-08 13:37 UTC

This package is auto-updated.

Last update: 2021-09-27 12:39:01 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.