extractAccessToken example

/** * @param AccessTokenExtractorInterface[] $accessTokenExtractors */
    public function __construct(
        private readonly iterable $accessTokenExtractors,
    ) {
    }

    public function extractAccessToken(Request $request): ?string
    {
        foreach ($this->accessTokenExtractors as $extractor) {
            if ($accessToken = $extractor->extractAccessToken($request)) {
                return $accessToken;
            }
        }

        return null;
    }
}
private readonly AccessTokenHandlerInterface $accessTokenHandler,
        private readonly AccessTokenExtractorInterface $accessTokenExtractor,
        private readonly ?UserProviderInterface $userProvider = null,
        private readonly ?AuthenticationSuccessHandlerInterface $successHandler = null,
        private readonly ?AuthenticationFailureHandlerInterface $failureHandler = null,
        private readonly ?string $realm = null,
    ) {
    }

    public function supports(Request $request): ?bool
    {
        return null === $this->accessTokenExtractor->extractAccessToken($request) ? false : null;
    }

    public function authenticate(Request $request): Passport
    {
        $accessToken = $this->accessTokenExtractor->extractAccessToken($request);
        if (!$accessToken) {
            throw new BadCredentialsException('Invalid credentials.');
        }

        $userBadge = $this->accessTokenHandler->getUserBadgeFrom($accessToken);
        if ($this->userProvider && (null === $userBadge->getUserLoader() || $userBadge->getUserLoader() instanceof FallbackUserLoader)) {
            
Home | Imprint | This part of the site doesn't use cookies.