Search code examples
phpsymfonyfosuserbundlefosrestbundlefosoauthserverbundle

OAuthStorage::__construct() must implement interface UserProviderInterface, instance of UserManager given


I am working on a simple rest API with OAuth authorization.

I followed the following tutorial to setup everything (I started with a clean installed symfony 3 application)

https://gist.github.com/tjamps/11d617a4b318d65ca583

After installing everything I changed the config.yml in the following way

fos_oauth_server:
 db_driver:           orm
 client_class:        UserBundle\Entity\Client
 access_token_class:  UserBundle\Entity\AccessToken
 refresh_token_class: UserBundle\Entity\RefreshToken
 auth_code_class:     UserBundle\Entity\AuthCode
 service:
     user_provider: fos_user.user_provider.username_email

I also the changed the security.yml to allow username and email on login

security:
encoders:
    FOS\UserBundle\Model\UserInterface: sha512
# http://symfony.com/doc/current/security.html#b-configuring-how-users-are-loaded
providers:
    in_memory:
        memory: ~
    fos_userbundle:
        id: fos_user.user_provider.username_email

firewalls:
    dev:
        pattern: ^/(_(profiler|wdt)|css|images|js)/
        security: false

    oauth_token:                                   # Everyone can access the access token URL.
        pattern: ^/oauth/v2/token
        security: false
    api:
        pattern: ^/                                # All URLs are protected
        fos_oauth: true                            # OAuth2 protected resource
        stateless: true                            # Do no set session cookies
        anonymous: false                           # Anonymous access is not allowed

Now I get the following error:

Fatal error: Uncaught exception 'Symfony\Component\Debug\Exception\ContextErrorException' with message 'Catchable Fatal Error: Argument 5 passed to FOS\OAuthServerBundle\Storage\OAuthStorage::__construct() must implement interface Symfony\Component\Security\Core\User\UserProviderInterface, instance of FOS\UserBundle\Doctrine\UserManager given, called in /Users/%username/rai-api/var/cache/prod/appProdProjectContainer.php on line 1614 and defined' in /Users/%username/rai-api/vendor/friendsofsymfony/oauth-server-bundle/Storage/OAuthStorage.php on line 80

I am using symfony 3.2


Solution

  • First, after making changes whenever you see this line

    var/cache/prod/appProdProjectContainer.php
    

    Always consider deleting the var/cache/prod folder and depending on you caching setup and/or what files you changed, restarting apache.

    Alternatively, just use the dev environment as it was meant to make your dev life easier although much slower.