passport icon indicating copy to clipboard operation
passport copied to clipboard

How to modify AuthCodeGrant?

Open gssj85 opened this issue 4 months ago • 1 comments

I need to override functionality of: vendor/league/oauth2-server/src/Grant/AuthCodeGrant.php to add another information on the authorization code (the tenant id), will also have to decrypt it later but for now I would be very happy to know how to override this one first.

So far I can say I have no idea how to do this, used some GPT help on a service provider but no success:

public function register(): void
    {
        Passport::ignoreRoutes();

        // Bind the AuthCodeRepositoryInterface to an implementation
        $this->app->bind(AuthCodeRepositoryInterface::class, AuthCodeRepository::class);

        // Optionally bind the RefreshTokenRepositoryInterface if you haven't done so
        $this->app->bind(RefreshTokenRepositoryInterface::class, RefreshTokenRepositoryInterface::class);

        parent::register();

        $this->app->extend(AuthorizationServer::class, function (AuthorizationServer $server) {
            $grant = new MyCustomAuthCodeGrant(
                $this->app->make(AuthCodeRepositoryInterface::class),
                $this->app->make(RefreshTokenRepositoryInterface::class),
                new \DateInterval('PT10M')
            );

            $server->enableGrantType($grant, new \DateInterval('PT1H'));

            return $server;
        });
    }

Those bind didnt help at all, got this error message:

Target [League\OAuth2\Server\Repositories\RefreshTokenRepositoryInterface] is not instantiable while building [Laravel\Passport\Http\Controllers\AuthorizationController].

gssj85 avatar Oct 01 '24 20:10 gssj85