Feat : implement token generation with facebook id

This commit is contained in:
2018-09-07 14:31:32 +02:00
parent 4edfae9f1c
commit 04229b0781
2 changed files with 34 additions and 0 deletions
@@ -66,6 +66,7 @@ security:
- { path: ^/entreprise/me/, roles: ROLE_COMPANY }
- { path: ^/territoire/me/, roles: ROLE_TERRITORY }
- { path: ^/api/login_check, roles: IS_AUTHENTICATED_ANONYMOUSLY}
- { path: ^/api/login_check_oauth, roles: IS_AUTHENTICATED_ANONYMOUSLY}
- { path: ^/api, roles: IS_AUTHENTICATED_FULLY, methods: [POST, PUT, DELETE, PATCH] }
- { path: ^/api, roles: IS_AUTHENTICATED_ANONYMOUSLY, methods: [GET]}
@@ -0,0 +1,33 @@
<?php
namespace AppBundle\Controller\Api;
use FOS\RestBundle\Controller\Annotations as Rest;
use FOS\RestBundle\Controller\Annotations\Post;
use FOS\RestBundle\Controller\Annotations\View;
use FOS\RestBundle\Controller\FOSRestController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
class SecurityController extends FOSRestController
{
/**
* @Rest\Post(path="/api/login_check_oauth", name="api_oauth_login")
* @Rest\View
*/
public function OAuthLoginAction(Request $request)
{
$jwtManager = $this->container->get('lexik_jwt_authentication.jwt_manager');
$token = $request->request->get('oauth-token');
$type = $request->request->get('oauth-type');
if ($type == "facebook") {
$em = $this->getDoctrine()->getManager();
$user = $em->getRepository('AppBundle:User')->findOneByFacebookId($token);
}
return new JsonResponse(['token' => $jwtManager->create($user)]);
}
}