klapaudius / FOSOAuthServerBundle

A server side OAuth2 Bundle for Symfony 5.0 or higher
7 stars 22 forks source link

Unable to inject OAuth Services #19

Closed LeoAdamek closed 8 months ago

LeoAdamek commented 8 months ago

Previously with the original version of this bundle, I was able to inject the fos_oauth_server.server and fos_oauth_server.storage.default services.

I use this as my authorization and client creation endpoints are implemented in GraphQL. However, in switching to your (very helpful!) fork, any method I try to inject these services fails.

I've tried using a service locator, but it errors with fos_oauth_server.server and fos_oauth_server.storage.default not existing. I've also tried directly injecting the OAuthStorage class which also fails as not existing.

./bin/console debug:container doesn't list either service so I'm confused as to what's going on because I can see their definitions are still present in this repo.

I'll continue to dig and see what I can find but I'm very confused!

My previous implementation looked like this:

# config/services.yaml
services:
  # Map the fos_oauth_server.server to the IOAuth2 interface type.
  OAuth2\IOAuth2:
    alias: fos_oauth_server.server 

  OAuth2\IOAuth2Storage:
    alias: fos_oauth_server.storage.default
# src/GraphQL/Mutations/OAuthMutation.php
class OAuthMutation {
  public function __constuct(
     /* ... other arguments */, 
    private readonly IOAuth2 $oauth2, 
    private readonly IOAuth2Storage $authStorage) 
  { }
}

However now neither service seems to exist and the container fails to compile.

LeoAdamek commented 8 months ago

Disregard, somehow in the process of swapping, the bundles.php config got mangled with the following:

FOS\OAuthServerBundle\FOSOAuthServerBundle::class => [0 => true, 1 => true] instead of ['all' => true]

Not sure how this happened but that meant the bundle wasn't even loaded!

klapaudius commented 8 months ago

Hello,

I'm glad that this repo helps you too. 😄