Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reduce reliance on ShopifyStoreInterface
- Loading branch information
1 parent
e7cc7bf
commit f2288eb
Showing
6 changed files
with
100 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
<?php | ||
|
||
namespace CodeCloud\Bundle\ShopifyBundle\Security; | ||
|
||
use CodeCloud\Bundle\ShopifyBundle\EventListener\SessionAuthenticationListener; | ||
use Symfony\Component\HttpFoundation\RedirectResponse; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpFoundation\Response; | ||
use Symfony\Component\Routing\Generator\UrlGeneratorInterface; | ||
use Symfony\Component\Security\Core\User\UserInterface; | ||
use Symfony\Component\Security\Guard\AbstractGuardAuthenticator; | ||
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; | ||
use Symfony\Component\Security\Core\Exception\AuthenticationException; | ||
use Symfony\Component\Security\Core\User\UserProviderInterface; | ||
|
||
/** | ||
* Authenticates users via session parameter. | ||
*/ | ||
class SessionAuthenticator extends AbstractGuardAuthenticator | ||
{ | ||
/** | ||
* @var UrlGeneratorInterface | ||
*/ | ||
private $urlGenerator; | ||
|
||
/** | ||
* @param UrlGeneratorInterface $urlGenerator | ||
*/ | ||
public function __construct(UrlGeneratorInterface $urlGenerator) | ||
{ | ||
$this->urlGenerator = $urlGenerator; | ||
} | ||
|
||
public function getCredentials(Request $request) | ||
{ | ||
if (!$session = $request->getSession()) { | ||
return false; | ||
} | ||
|
||
if (!$session->has(SessionAuthenticationListener::SESSION_PARAMETER)) { | ||
return false; | ||
} | ||
|
||
return [ | ||
'shop' => $session->get(SessionAuthenticationListener::SESSION_PARAMETER), | ||
]; | ||
} | ||
|
||
public function getUser($credentials, UserProviderInterface $userProvider) | ||
{ | ||
return $userProvider->loadUserByUsername($credentials['shop']); | ||
} | ||
|
||
public function checkCredentials($credentials, UserInterface $user) | ||
{ | ||
return true; | ||
} | ||
|
||
public function onAuthenticationFailure(Request $request, AuthenticationException $exception) | ||
{ | ||
} | ||
|
||
public function onAuthenticationSuccess(Request $request, TokenInterface $token, $providerKey) | ||
{ | ||
} | ||
|
||
public function supportsRememberMe() | ||
{ | ||
return false; | ||
} | ||
|
||
public function start(Request $request, AuthenticationException $authException = null) | ||
{ | ||
if (!$request->get('shop')) { | ||
return new Response('Your session has expired. Please access the app via Shopify Admin again.'); | ||
} | ||
|
||
return new RedirectResponse( | ||
$this->urlGenerator->generate('codecloud_shopify_auth', [ | ||
'shop' => $request->get('shop'), | ||
]) | ||
); | ||
} | ||
} |