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

Security manager update #292

Open
wants to merge 17 commits into
base: v3.x
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Implement new security features since SF 5.3
ricohumme committed Sep 6, 2021
commit 9c1f1fff213ed656c0f208a7964874bb082135ce
3 changes: 1 addition & 2 deletions Security/Authentication/Provider/OAuth2Provider.php
Original file line number Diff line number Diff line change
@@ -7,15 +7,14 @@
use League\OAuth2\Server\Exception\OAuthServerException;
use League\OAuth2\Server\ResourceServer;
use RuntimeException;
use Symfony\Component\Security\Core\Authentication\Provider\AuthenticationProviderInterface;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Exception\AuthenticationException;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Security\Core\User\UserProviderInterface;
use Trikoder\Bundle\OAuth2Bundle\Security\Authentication\Token\OAuth2Token;
use Trikoder\Bundle\OAuth2Bundle\Security\Authentication\Token\OAuth2TokenFactory;

final class OAuth2Provider implements AuthenticationProviderInterface
final class OAuth2Provider
{
/**
* @var UserProviderInterface
22 changes: 18 additions & 4 deletions Security/Guard/Authenticator/OAuth2Authenticator.php
Original file line number Diff line number Diff line change
@@ -14,7 +14,10 @@
use Symfony\Component\Security\Core\Exception\AuthenticationException;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Security\Core\User\UserProviderInterface;
use Symfony\Component\Security\Guard\AuthenticatorInterface;
use Symfony\Component\Security\Http\Authenticator\AbstractAuthenticator;
use Symfony\Component\Security\Http\Authenticator\Passport\Badge\UserBadge;
use Symfony\Component\Security\Http\Authenticator\Passport\PassportInterface;
use Symfony\Component\Security\Http\Authenticator\Passport\SelfValidatingPassport;
use Trikoder\Bundle\OAuth2Bundle\Security\Authentication\Token\OAuth2Token;
use Trikoder\Bundle\OAuth2Bundle\Security\Authentication\Token\OAuth2TokenFactory;
use Trikoder\Bundle\OAuth2Bundle\Security\Exception\InsufficientScopesException;
@@ -24,7 +27,7 @@
* @author Yonel Ceruto <yonelceruto@gmail.com>
* @author Antonio J. García Lagar <aj@garcialagar.es>
*/
final class OAuth2Authenticator implements AuthenticatorInterface
final class OAuth2Authenticator extends AbstractAuthenticator
{
private $httpMessageFactory;
private $resourceServer;
@@ -73,9 +76,9 @@ public function checkCredentials($token, UserInterface $user): bool
return true;
}

public function createAuthenticatedToken(UserInterface $user, $providerKey): OAuth2Token
public function createAuthenticatedToken(PassportInterface $passport, $providerKey): TokenInterface
{
$tokenUser = $user instanceof NullUser ? null : $user;
$tokenUser = $passport instanceof NullUser ? null : $passport->getUser();

$oauth2Token = $this->oauth2TokenFactory->createOAuth2Token($this->psr7Request, $tokenUser, $providerKey);

@@ -100,6 +103,17 @@ public function onAuthenticationSuccess(Request $request, TokenInterface $token,
return $this->psr7Request = null;
}

public function authenticate(Request $request): PassportInterface
{
if (null === $this->psr7Request) {
$this->getCredentials($request);
}

$token = $this->psr7Request->getAttribute('oauth_user_id');

return new SelfValidatingPassport(new UserBadge($token));
}

public function supportsRememberMe(): bool
{
return false;