# Auth0/symfony Management APIs

**URL:** <https://community.auth0.com/t/auth0-symfony-management-apis/125361>\
**Category:** Get Help\
**Tags:** sdks-quickstarts, auth0-php\
**Created:** [January 22, 2024, 3:42pm UTC](https://community.auth0.com/t/auth0-symfony-management-apis/125361 "2024-01-22T15:42:14Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![geert.huygen](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@geert.huygen](https://community.auth0.com/u/geert.huygen)\
**Post date:** [January 22, 2024, 3:42pm UTC](https://community.auth0.com/t/auth0-symfony-management-apis/125361/1 "2024-01-22T15:42:14Z")

</div>

Hey,

I would like to work with the management part of the sdk.  
But i can’t seem to find any docs regarding the symfony sdk.

I looked add the source code but i can’t seem to find any service a can inject in my services.  
what is the best approach to do this, are there any examples?

I’m looking to manage the users from within my symfony project.

thx!

---

<div class="post-metadata">

**Author:** ![evansims](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/evansims/32/27011_2.png) [@evansims](https://community.auth0.com/u/evansims)\
**Post date:** [January 23, 2024, 7:02pm UTC](https://community.auth0.com/t/auth0-symfony-management-apis/125361/2 "2024-01-23T19:02:34Z")

</div>

Hi @geert.huygen 👋 Thanks for your question. That’s a great point — we should do better at explaining how to use the Management APIs from that SDK.

At present, we don’t expose this API through a Symfony service; nevertheless, it can be used by directly calling the underlying [Auth0-PHP SDK](https://github.com/auth0/auth0-PHP) instance already instantiated and configured by your Symfony SDK instance.

Here’s an example of accessing Management API endpoints in this manner:

> Note: I’m writing this from memory as I’m not at my machine at the moment, so this probably won’t work exactly as-is and may require minor adjustments.

```php
<?php

declare(strict_types=1);

namespace App\Example\Controllers;

use Auth0\SDK\Auth0;
use Auth0\Symfony\Security\Authenticator;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;

final class ExampleController extends AbstractController
{
    public function __construct(
        private Authenticator $authenticator,
        private RouterInterface $router,
    ) {
    }

    public function updateUserColorMetadata(Request $request): Response
    {
        $user = $this->getUser();
        $endpoint = $this->getManagement()->users();

        $colors = ['red', 'blue', 'green', 'black', 'white', 'yellow', 'purple', 'orange', 'pink', 'brown'];

        // Update the user's metadata with the Management API.
        $endpoint->update(
            id: $user()->getId(),
            body: [
                'user_metadata' => [
                    'color' => $colors[random_int(0, count($colors) - 1)]
                ]
            ]
        );

        $metadata = $endpoint->get($user->getId()); // Retrieve the user's updated metadata.
        $metadata = json_decode($metadata->getBody(), true); // JSON -> PHP array.

        $color = $metadata['user_metadata']['color'] ?? 'unknown';
        $name = $user->getName();

        return new Response("Hello {$name}! Your favorite color is now {$color}.");
    }

    private function getManagement()
    {
        return $this->getSdk()->management();
    }

    private function getSdk(): Auth0
    {
        return $this->authenticator->service->getSdk();
    }
}

```

Usage reference for the `management()` class can be found here: [auth0-PHP/docs/Management.md at main · auth0/auth0-PHP · GitHub](https://github.com/auth0/auth0-PHP/blob/main/docs/Management.md)

---

<div class="post-metadata">

**Author:** ![geert.huygen](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@geert.huygen](https://community.auth0.com/u/geert.huygen)\
**Post date:** [January 24, 2024, 9:57am UTC](https://community.auth0.com/t/auth0-symfony-management-apis/125361/3 "2024-01-24T09:57:05Z")

</div>

Hey, first of all, thanks for the reply.

Unfortunately, every service is private and not available for dependency injection.

The `Authenticator` has no function or prop called `service`  
I believe you meant the `Authorizer` class.  
This class has a `getService` methode.  
However, this service is not accessible. Here’s the output from the Symfony CLI `debug:container`:

```auto
Information for Service "auth0.authorizer"
==========================================

 ---------------- ------------------------------------- 
  Option Value                                
 ---------------- ------------------------------------- 
  Service ID auth0.authorizer                     
  Class Auth0\Symfony\Security\Authorizer    
  Tags -                                    
  Public no                                   
  Synthetic no                                   
  Lazy no                                   
  Shared yes                                  
  Abstract no                                   
  Autowired no                                   
  Autoconfigured no                                   
  Usages security.command.debug_firewall      
                   security.authenticator.manager.main  
                   .service_locator.6OJrPuT             
 ---------------- ------------------------------------- 

 ! [NOTE] The "auth0.authorizer" service or alias has been removed or inlined when the container was compiled.   

```

I think I’m just going to use the [Auth0-PHP SDK](https://github.com/auth0/auth0-PHP) package and wrap this with a service of my own.

---

<div class="post-metadata">

**Author:** ![evansims](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/evansims/32/27011_2.png) [@evansims](https://community.auth0.com/u/evansims)\
**Post date:** [January 24, 2024, 6:46pm UTC](https://community.auth0.com/t/auth0-symfony-management-apis/125361/4 "2024-01-24T18:46:32Z")

</div>

Hi @geert.huygen

> Unfortunately, every service is private and not available for dependency injection.

Hmm, the underlying SDK instance is absolutely intended for accessibility to the host app for cases like this

> I believe you meant the `Authorizer` class.  
> The `Authenticator` has no function or prop called `service`

For Authorizer, there’s [a public method](https://github.com/auth0/symfony/blob/5a204087283f54ab4431ac045eec1044b768580e/src/Security/Authorizer.php#L78C21-L78C31) to retrieve the service instance from the Authorizor class called `getService()`.

For Authenticator, the `service` property [is public on the Authenticator class](https://github.com/auth0/symfony/blob/5a204087283f54ab4431ac045eec1044b768580e/src/Security/Authenticator.php#L32).

> However, this service is not accessible. Here’s the output from the Symfony CLI `debug:container`:

It sounds like your service instance may not have been initialized before it was called. In your app’s case, the framework firewall may not have booted up the service before you attempted to call it. You can define a service to always be available through your application’s `services.yaml` file.

> I think I’m just going to use the Auth0-PHP SDK package and wrap this with a service of my own.

That’s a totally valid approach as well! 🙂

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [February 7, 2024, 6:47pm UTC](https://community.auth0.com/t/auth0-symfony-management-apis/125361/5 "2024-02-07T18:47:27Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
