Adds SSL support for Discord login
This commit is contained in:
parent
d67c4063e4
commit
41a12d9a82
3 changed files with 14 additions and 4 deletions
|
@ -37,4 +37,9 @@ final class EnvironmentHandler
|
||||||
public function isProduction(): bool {
|
public function isProduction(): bool {
|
||||||
return $_SERVER['PRODUCTION'] === 'true';
|
return $_SERVER['PRODUCTION'] === 'true';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function useSSL(): bool
|
||||||
|
{
|
||||||
|
return $_SERVER['USE_SSL'] === 'true';
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -7,12 +7,14 @@ use Doctrine\ORM\EntityManager;
|
||||||
use GamesShop\Api\DiscordAPI;
|
use GamesShop\Api\DiscordAPI;
|
||||||
use GamesShop\ContainerHandler;
|
use GamesShop\ContainerHandler;
|
||||||
use GamesShop\Entities\Account\User;
|
use GamesShop\Entities\Account\User;
|
||||||
|
use GamesShop\Environment\EnvironmentHandler;
|
||||||
use Psr\Http\Message\ServerRequestInterface;
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
|
|
||||||
final class DiscordLoginProvider implements LoginProvider
|
final class DiscordLoginProvider implements LoginProvider
|
||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
private readonly EntityManager $entityManager
|
private readonly EntityManager $entityManager,
|
||||||
|
private readonly EnvironmentHandler $env
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -20,7 +22,12 @@ final class DiscordLoginProvider implements LoginProvider
|
||||||
public function getUser(ServerRequestInterface $request): User
|
public function getUser(ServerRequestInterface $request): User
|
||||||
{
|
{
|
||||||
$discordApiHandler = ContainerHandler::get(DiscordAPI::class);
|
$discordApiHandler = ContainerHandler::get(DiscordAPI::class);
|
||||||
$result = $discordApiHandler->getUserFromCode($request->getQueryParams()['code'], (string)$request->getUri()->withQuery(''));
|
$result = $discordApiHandler->getUserFromCode(
|
||||||
|
$request->getQueryParams()['code'],
|
||||||
|
(string)$request->getUri()
|
||||||
|
->withScheme($this->env->useSSL() ? 'https' : 'http')
|
||||||
|
->withQuery('')
|
||||||
|
);
|
||||||
|
|
||||||
$repo = $this->entityManager->getRepository(User::class);
|
$repo = $this->entityManager->getRepository(User::class);
|
||||||
$users = $repo->findBy(['loginMethod' => LoginMethod::DISCORD, 'foreignLoginId' => $result['id']]);
|
$users = $repo->findBy(['loginMethod' => LoginMethod::DISCORD, 'foreignLoginId' => $result['id']]);
|
||||||
|
|
|
@ -15,8 +15,6 @@ require_once __DIR__ . '/../src/php/bootstrap.php';
|
||||||
|
|
||||||
ContainerHandler::get(CrashHandler::class)->register();
|
ContainerHandler::get(CrashHandler::class)->register();
|
||||||
|
|
||||||
throw new Exception();
|
|
||||||
|
|
||||||
$router = ContainerHandler::getInstance()->get(Router::class);
|
$router = ContainerHandler::getInstance()->get(Router::class);
|
||||||
$result = $router->route();
|
$result = $router->route();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue