diff --git a/.env b/.env index ee0f752..54052e9 100644 --- a/.env +++ b/.env @@ -1,18 +1,9 @@ -###> symfony/framework-bundle ### APP_ENV=dev APP_SECRET= APP_SHARE_DIR=var/share APP_VERSION=0.0.1 -###< symfony/framework-bundle ### - -###> doctrine/doctrine-bundle ### DATABASE_URL="postgresql://app:!ChangeMe!@127.0.0.1:5432/app?serverVersion=16&charset=utf8" -###< doctrine/doctrine-bundle ### - -###> symfony/mailer ### MAILER_DSN="smtp://localhost:1025" -###< symfony/mailer ### - -###> symfony/routing ### DEFAULT_URI="http://localhost:8000" -###< symfony/routing ### \ No newline at end of file +KAZ_API_USER= +KAZ_API_PASSWORD= \ No newline at end of file diff --git a/config/packages/framework.yaml b/config/packages/framework.yaml index 7e1ee1f..a5d3d9c 100644 --- a/config/packages/framework.yaml +++ b/config/packages/framework.yaml @@ -1,13 +1,14 @@ -# see https://symfony.com/doc/current/reference/configuration/framework.html framework: secret: '%env(APP_SECRET)%' - - # Note that the session will be started ONLY if you read or write from it. session: true + http_client: + scoped_clients: + kaz_api.client: + base_uri: '%env(KAZ_API_BASE_URL)%' + headers: + Accept: 'application/json' - #esi: true - #fragments: true - +# Section pour les tests when@test: framework: test: true diff --git a/config/services.yaml b/config/services.yaml index a39419d..e66afcb 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -1,21 +1,14 @@ -# yaml-language-server: $schema=../vendor/symfony/dependency-injection/Loader/schema/services.schema.json - -# This file is the entry point to configure your own services. -# Files in the packages/ subdirectory configure your dependencies. -# See also https://symfony.com/doc/current/service_container/import.html - -# Put parameters here that don't need to change on each machine where the app is deployed -# https://symfony.com/doc/current/best_practices.html#use-parameters-for-application-configuration services: - # default configuration for services in *this* file + # configuration par défaut pour les services _defaults: - autowire: true # Automatically injects dependencies in your services. - autoconfigure: true # Automatically registers your services as commands, event subscribers, etc. + autowire: true # Injecte automatiquement les dépendances dans vos services. + autoconfigure: true # Enregistre automatiquement vos services en tant que commandes, abonnés d'événements, etc. - # makes classes in src/ available to be used as services - # this creates a service per class whose id is the fully-qualified class name App\: resource: '../src/' - # add more service definitions when explicit configuration is needed - # please note that last definitions always *replace* previous ones + App\Service\KazApiClient: + arguments: + $kazApiClient: '@kaz_api.client' + $apiUser: '%env(KAZ_API_USER)%' + $apiPassword: '%env(KAZ_API_PASSWORD)%' \ No newline at end of file diff --git a/src/Controller/UserController.php b/src/Controller/UserController.php new file mode 100644 index 0000000..c01b478 --- /dev/null +++ b/src/Controller/UserController.php @@ -0,0 +1,39 @@ +getUserData($email); + + return $this->render('user/index.html.twig', [ + 'exist' => $exist, + ]); + } +} \ No newline at end of file diff --git a/src/Service/KazApiService.php b/src/Service/KazApiService.php new file mode 100644 index 0000000..54fb8cc --- /dev/null +++ b/src/Service/KazApiService.php @@ -0,0 +1,80 @@ +token) { + return $this->token; + } + + $response = $this->kazApiClient->request('POST', '/get_token', [ + 'auth_basic' => [$this->apiUser, $this->apiPassword] + ]); + + if ($response->getStatusCode() !== 200) { + throw new Exception('Impossible de récupérer le token JWT'); + } + + $data = $response->toArray(); + $this->token = $data['token']; // Ajustez la clé selon le format de votre API + + return $this->token; + } + + /** + * Permet de vérifier si un utilisateur existe dans le ldap. + * + * @param string $email L'adresse e-mail de l'utilisateur à rechercher. + * + * @return array Les données utilisateur renvoyées par l'API. + * + * @throws ClientExceptionInterface + * @throws DecodingExceptionInterface + * @throws RedirectionExceptionInterface + * @throws ServerExceptionInterface + * @throws TransportExceptionInterface + * @throws Exception + */ + public function getUserData(string $email): array + { + $options['headers']['Authorization'] = 'Bearer ' . $this->getToken(); + + $response = $this->kazApiClient->request('GET', "/ldap/user/$email", $options); + + if ($response->getStatusCode() !== 200) { + throw new Exception('Erreur lors de l\'appel API : ' . $response->getStatusCode()); + } + + return $response->toArray(); + } +} \ No newline at end of file diff --git a/templates/user/index.html.twig b/templates/user/index.html.twig new file mode 100644 index 0000000..bf1df76 --- /dev/null +++ b/templates/user/index.html.twig @@ -0,0 +1,2 @@ +{# templates/hellp.html.twig #} +

Hello ! {{ name }}

\ No newline at end of file