M
M
Maxim Lagoysky2019-10-11 17:21:25
symfony
Maxim Lagoysky, 2019-10-11 17:21:25

How to customize the response of receiving a token in FosOauthServer?

I want to customize the default response to receive the "/oauth/v2/token" token from the FosOauthServer bundle. I create a TokenController that extends the FosOAuthServerBundle controller.

<?php

namespace App\Controller;

use OAuth2\OAuth2;
use Symfony\Component\HttpFoundation\Request;
use FOS\OAuthServerBundle\Controller\TokenController as BaseController;

class TokenController extends BaseController
{
    /**
     * @param OAuth2 $server
     */
    public function __construct(OAuth2 $server)
    {
        parent::__construct($server);
    }

    public function tokenAction(Request $request)
    {
        // Do whatever you like here
        $result = parent::tokenAction($request);
        // More custom code.
        return $result;
    }
}

In the service.yaml config I write
OAuth2\OAuth2:
        arguments:
            $storage: fos_oauth_server.storage
            $config: '%fos_oauth_server.server.options%'

    FOS\OAuthServerBundle\Controller\TokenController:
        class: App\Controller\TokenController
        arguments:
            $server: fos_oauth_server.server.class

But I am getting an error

Argument 1 passed to App\\Controller\\TokenController::__construct() must be an instance of OAuth2\\OAuth2, string given, called in /var/www/api-support.local/var/cache/dev/ContainerGFSkCmR/ getFosOauthServer_Controller_TokenService.php on line 12

and I still can’t figure out what I didn’t do correctly, but I guess I made a mess in service.yaml.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Antony Tkachenko, 2019-10-11
@lagoy

To pass services as an argument, use @service.id
You are passing the string
https://symfony.com/doc/current/service_container....

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question