auth0 / auth0-PHP

PHP SDK for Auth0 Authentication and Management APIs.
https://auth0.com/docs/libraries/auth0-php
MIT License
381 stars 210 forks source link

Unable to retrieve Management API access token due to change in 8.4.0 #705

Closed chrisnetonline closed 1 year ago

chrisnetonline commented 1 year ago

Checklist

SDK Version

8.3

PHP Version

PHP 8.1

Description

This is a regression in the new 8.4 SDK.

The new addClientAuthentication method introduced in feat(Authentication): Add support for Client Assertion #699 is overwriting the Management API client_id and client_secret with the Authentication client_id and client_secret set in the following sample code:

    protected function obtainManagementToken(Auth0Interface $client): void
    {
        $response = $client->authentication()->clientCredentials([
            'audience' => 'https://' . $this->config['domain'] . '/api/v2/',
            'client_id' => $this->config['management']['client_id'],
            'client_secret' => $this->config['management']['client_secret'],
        ]);

        if ($response->getStatusCode() >= 300) {
            Log::error('Auth0AuthorizationService@obtainManagementToken: Unexpected response', [
                'responseBody' => $response->getBody()->getContents(),
                'responseCode' => $response->getStatusCode(),
            ]);

            throw new RequestException(
                message: 'Unexpected status code: ' . $response->getReasonPhrase(),
                code: $response->getStatusCode(),
            );
        }

        $responseData = json_decode($response->getBody());

        $client->configuration()->setManagementToken($responseData?->access_token);
    }

    protected function getClient(): Auth0Interface
    {
        return new Auth0([
            'domain' => $this->config['domain'],
            'clientId' => $this->config['client_id'],
            'clientSecret' => $this->config['client_secret'],
            'cookieSecret' => $this->config['cookie_secret'],
            'cookieDomain' => $this->config['cookie_domain'],
        ]);
    }

This works fine in 8.3.8 and is broken in 8.4.0.

How can we reproduce this issue?

See notes above.

evansims commented 1 year ago

Hey @chrisnetonline πŸ‘‹ Thanks very much for bringing this to my attention! I'll get a fix prepared.

chrisnetonline commented 1 year ago

Any update on this? Can I help in any way?

evansims commented 1 year ago

Hi @chrisnetonline πŸ‘‹ Thanks for being patient, the team has been at an offsite this past week. We've prepared a fix that will ship with 8.5.0 this week.