0

I've installed fosOauthServerBundle with a custom authentification provider (avoiding FosUserBundle).

It seems that the configuration of my service isn't accurate, so the bundle can't find the user provider :

Call to a member function loadUserByUsername() on null

refering to :vendor\friendsofsymfony\oauth-server-bundle\Storage\OAuthStorage.php (line 162)

try {
       $user = $this->userProvider->loadUserByUsername($username);
    } catch (AuthenticationException $e) { 
       return false; 
   }

Hopefully a post already treat this kind of error, but it doesn't suggest explicit solution :

previous topic same issue

I am using the entity provider as in the documentation which does work perfectly using everything except for grant password using fosoauth (frustrating) : entity user provider link

I actually tried a couple of way to write it in the config service but couldn't make it work. Can anyone propose to me a solution?

I've tried app_user_provider.email or app_user_provider.username but it doesn't work either.

security:
encoders:
  App\Entity\User:
    algorithm: bcrypt
    #FOS\UserBundle\Model\UserInterface: bcrypt

role_hierarchy:
    ROLE_ADMIN:       ROLE_USER, ROLE_ESTABLISHMENT
    ROLE_SUPER_ADMIN: ROLE_ADMIN

providers:
    app_user_provider:
        entity:
            class: App\Entity\User
            property: email

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

    oauth_token:
        pattern: ^/oauth/v2/token
        security: false

    # Add this firewall only in the Authorization code flow
    oauth_authorize:
        pattern: ^/oauth/v2/auth
        form_login:
            provider: app_user_provider
            check_path: /oauth/v2/auth_login_check
            login_path: /oauth/v2/auth_login
        anonymous: true

    api_doc:
        pattern: ^/api/doc
        fos_oauth: false
        stateless: true
        anonymous: true

    api:
        pattern: ^/api
        fos_oauth: true
        stateless: true
        anonymous: false

    main:
        pattern: ^/
        form_login:
            provider: app_user_provider
            csrf_token_generator: security.csrf.token_manager
        #logout: true
        guard:
            authenticators:
                - App\Security\LoginFormAuthenticator
        remember_me:
            secret:   '%kernel.secret%'
            lifetime: 604800 # 1 week in seconds
            path:     /
            always_remember_me: true
        logout:
            path: app_logout
            target: app_login
        fos_oauth: false
        anonymous: true

access_control:
    - { path: ^/oauth/v2/auth_login$, role: IS_AUTHENTICATED_ANONYMOUSLY } # Add this only in the Authorization code flow
    - { path: ^/api/doc, roles: IS_AUTHENTICATED_ANONYMOUSLY }
    - { path: ^/api, roles: IS_AUTHENTICATED_FULLY }
    - { path: ^/login, role: IS_AUTHENTICATED_ANONYMOUSLY }
    - { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
    - { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }
    - { path: ^/establishment, role: IS_AUTHENTICATED_ANONYMOUSLY }

fos_oauth_server:
db_driver:           orm
client_class:        App\Entity\Client
access_token_class:  App\Entity\AccessToken
refresh_token_class: App\Entity\RefreshToken
auth_code_class:     App\Entity\AuthCode
service:
    #user_provider: fos_user.user_provider.username
    user_provider: app_user_provider

That would save my day, thanks !

El mago
  • 11
  • 2

1 Answers1

0

Okay, I just have to create a custom user provider. It can't work on the entity.

https://symfony.com/doc/current/security/user_provider.html#creating-a-custom-user-provider

El mago
  • 11
  • 2