Skip to content

Commit

Permalink
added token auth
Browse files Browse the repository at this point in the history
  • Loading branch information
raphaelbadawi committed Jul 1, 2021
1 parent aaa2ee8 commit 999000a
Show file tree
Hide file tree
Showing 15 changed files with 465 additions and 31 deletions.
2 changes: 2 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"doctrine/doctrine-migrations-bundle": "^3.1",
"doctrine/orm": "^2.9",
"easycorp/easyadmin-bundle": "^3.3",
"fzaninotto/faker": "^1.5",
"knplabs/knp-markdown-bundle": "^1.9",
"knpuniversity/oauth2-client-bundle": "^2.8",
"league/oauth2-google": "^4.0",
Expand Down Expand Up @@ -51,6 +52,7 @@
"twig/twig": "^2.12|^3.0"
},
"require-dev": {
"doctrine/doctrine-fixtures-bundle": "^3.4",
"phpunit/phpunit": "^9.5",
"symfony/browser-kit": "^5.3",
"symfony/css-selector": "^5.3",
Expand Down
219 changes: 217 additions & 2 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions config/bundles.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@
EasyCorp\Bundle\EasyAdminBundle\EasyAdminBundle::class => ['all' => true],
Nelmio\CorsBundle\NelmioCorsBundle::class => ['all' => true],
ApiPlatform\Core\Bridge\Symfony\Bundle\ApiPlatformBundle::class => ['all' => true],
Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle::class => ['dev' => true, 'test' => true],
];
2 changes: 2 additions & 0 deletions config/packages/security.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ security:
custom_authenticators:
- App\Security\LoginFormAuthenticator
- App\Security\GoogleAuthenticator
- App\Security\ApiTokenAuthenticator
entry_point: App\Security\LoginFormAuthenticator
logout:
path: app_logout
# where to redirect after logout
Expand Down
19 changes: 19 additions & 0 deletions src/Controller/QuackController.php
Original file line number Diff line number Diff line change
Expand Up @@ -297,4 +297,23 @@ public function search(HttpClientInterface $httpClient, EntityManagerInterface $
'searchValue' => $request->query->get('q')
]);
}

#[Route('api/quacks/s', name: 'api_search_quack')]
public function apiSearch(HttpClientInterface $httpClient, EntityManagerInterface $entityManager, Request $request): Response
{
$foundQuacks = $httpClient->request('POST', $_ENV['ELASTICSEARCH_ENDPOINT'] . '/quacks/_doc/_search', [
"json" => [
"query" => [
"match" => [
"tags" => $request->query->get('q')
]
]
]
]);

// get the results
$foundQuacks = json_decode($foundQuacks->getContent())->hits->hits;

return $this->json($foundQuacks, 200, []);
}
}
12 changes: 12 additions & 0 deletions src/Controller/SecurityController.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,18 @@

class SecurityController extends AbstractController
{
#[Route('/api/whoami', name: "api_whoami")]
public function accountApi(Request $request, EntityManagerInterface $entityManager)
{
$this->denyAccessUnlessGranted('ROLE_USER');

$user = $this->getUser();
$duck = $entityManager->getRepository(Duck::class)->findOneBy(['id' => $user->getId()]);
return $this->json($duck, 200, [], [
'groups' => ['duck:read'],
]);
}

#[Route('/connect/google', name: "connect_google_start")]
public function connectAction(ClientRegistry $clientRegistry)
{
Expand Down
17 changes: 17 additions & 0 deletions src/DataFixtures/AppFixtures.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace App\DataFixtures;

use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Persistence\ObjectManager;

class AppFixtures extends Fixture
{
public function load(ObjectManager $manager)
{
// $product = new Product();
// $manager->persist($product);

$manager->flush();
}
}
Loading

0 comments on commit 999000a

Please sign in to comment.