Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2.x not compatible with \Symfony\Component\Security\Http\Authentication\AuthenticatorManager::authenticateUser #1971

Closed
muhammedeminakbulut opened this issue Dec 6, 2023 · 2 comments

Comments

@muhammedeminakbulut
Copy link

Q A
Bug? yes
New Feature? no
Support question? no
Version 2.1.0

Actual Behavior

Fatal error: 
The first argument of "HWI\Bundle\OAuthBundle\Security\Http\Authenticator\OAuthAuthenticator::createAuthenticatedToken" must be instance of "HWI\Bundle\OAuthBundle\Security\Http\Authenticator\Passport\SelfValidatedOAuthPassport", "Symfony\Component\Security\Http\Authenticator\Passport\SelfValidatingPassport" provided.

Expected Behavior

Authenticate the user. We use this in tests to have a fake user logged in. This previously worked with 1.4.x

Steps to Reproduce

use HWI\Bundle\OAuthBundle\Security\Core\User\OAuthUser;
use HWI\Bundle\OAuthBundle\Security\Http\Authenticator\OAuthAuthenticator;
use Symfony\Bundle\SecurityBundle\Security\UserAuthenticator;
use Symfony\Component\HttpFoundation\Request;

class FakeLoginController
{
    public function __construct(
        private readonly OAuthAuthenticator $authenticator,
        private readonly UserAuthenticator $userAuthenticator,
    ) {
    }

    public function fakeLogin(Request $request)
    {
        return $this->userAuthenticator->authenticateUser(new OAuthUser('fake.user@fakedomain.nl'), $this->authenticator, $request);
    }
}

@stloyd
Copy link
Collaborator

stloyd commented Feb 9, 2024

This is a bit more complicated because the authenticateUser() method has a hardcoded relation to Symfony SelfValidatedOAuthPassport class, while this bundle supports a much wider amount of Symfony versions has its class with BC code (for Symfony 5.4), second thing is that we store there OAuthToken to use it internally.

That's the reason for the fatal error when using Symfony authenticator with HWI one possible solution could be the usage of a custom badge to hold OAuthToken instead of a passport.

@stloyd
Copy link
Collaborator

stloyd commented Feb 9, 2024

@muhammedeminakbulut (or others who like the issue), can you try playing with code from: #1976 ?

@stloyd stloyd closed this as completed Feb 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants