Bonjour,

Voila je rencontre un petit problème avec mon code.

Jwt token

Je développe actuellement mon premier Api paltform et, lorsque je teste la fonction RegisterUserAction, je rencontre ce problème.
"An error occurred while trying to encode the JWT token. Please verify your configuration (private key/passphrase)","
"It was not possible to parse your key, reason: error:0909006C:PEM routines:get_name:no start line"
je ne sais pas quoi faire

function registerUserAction

 /**
 * Register a new User
 *
 * @param Request $request
 * @throws \Exception
 *
 * @Annotations\Post("/register-User")
 * @SWG\Parameter(
 *     name="form",
 *     in="body",
 *     description="Request Body Params",
 *     @Model(type=CoreBundle\Form\Type\User\UserType::class)
 * )
 * @SWG\Response(response=400, description="User Already exist")
 * @SWG\Response(response=201, description="Particular successfully created")
 */
public function registerUserAction(Request $request)
{

    $manager = $this->get('doctrine.orm.entity_manager');

    $url = $request->headers->get('referer');
    $referer = $url ? str_ireplace('www.', '', parse_url($url)['host']) : '';

    /** @var FormFactory $formFactory */
    $formFactory = $this->get('form.factory');
    /** @var $userManager \FOS\UserBundle\Model\UserManagerInterface */
    $userManager = $this->get('fos_user.user_manager');
    /** @var $dispatcher \Symfony\Component\EventDispatcher\EventDispatcherInterface */
    $dispatcher = $this->get('event_dispatcher');

    /** @var User $user */
    $user = $userManager->createUser();
    $user->setEnabled(false);
    $user->setRoles(['ROLE_User']);
    $token = $this->get('fos_user.util.token_generator')->generateToken();
    $user->setConfirmationToken($token);

    $event = new GetResponseUserEvent($user, $request);
    $dispatcher->dispatch(FOSUserEvents::REGISTRATION_INITIALIZE, $event);

    if (null !== $event->getResponse()) {
        return $event->getResponse();
    }

    /**
     * @var FormInterface $form
     */
    $form = $formFactory->create(UserType::class, null, [
        'csrf_protection' => false,
    ]);

    $form->setData($user);
    $data = $request->request->all();
    $form->submit($data);
    $user->setUsername($user->getEmail());
    /**
     * @var UserRepository $userRepo
     */
    $userRepo = $manager->getRepository(User::class);

    $existUser = $userRepo->findOneBy(['email' => $user->getEmail()]);
    if ($existUser) {
        throw new \Exception(
            'The specified user already exist',
            Response::HTTP_BAD_REQUEST
        );
    }

    if (!$form->isValid()) {

        $event = new FormEvent($form, $request);

        $dispatcher->dispatch(FOSUserEvents::REGISTRATION_FAILURE, $event);

        if (null !== $response = $event->getResponse()) {
            return $response;
        }
        return $form;
    }
    $event = new FormEvent($form, $request);
    $dispatcher->dispatch(FOSUserEvents::REGISTRATION_SUCCESS, $event);

    if ($event->getResponse()) {
        return $event->getResponse();
    }

    $userManager->updateUser($user);

    $token = $this->get('lexik_jwt_authentication.jwt_manager')->create($user);
    $tokenType = $this->getParameter('jwt_type');
    $expiresIn = $this->getParameter('jwt_token_ttl');
    $date = new \DateTime();
    $date->setTimeZone(new \DateTimeZone('UTC'));
    $date->add(new \DateInterval('PT' . $expiresIn . 'S'));
    $expiresAt = $date->format('Y-m-d\TH:i:s.\0\0\0\Z');

}

entité user

<?php

namespace CoreBundle\Doctrine\Entity\User;

use CoreBundle\Doctrine\Entity\Core\Address;
use CoreBundle\Doctrine\Entity\Core\I18N;
use CoreBundle\Doctrine\Entity\Core\Image;
use CoreBundle\Doctrine\Entity\Categorie\Professional;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use FOS\UserBundle\Model\User as BaseUser;
use JMS\Serializer\Annotation as Serializer;
use Symfony\Component\Validator\Constraints as Assert;

/**
 * User
 * @ORM\Entity
 * @ORM\Table(
 *     name="us_user",
 * )
 * @ORM\Entity(repositoryClass="CoreBundle\Doctrine\Repository\User\UserRepository")
 */
class User extends BaseUser
{

    /**
     * @var string
     * @ORM\Id
     * @ORM\Column(name="id", type="guid")
     * @ORM\GeneratedValue(strategy="UUID")
     * @Serializer\Groups({"UserList", "UserDetail"})
     */
    protected $id;

    /**
     * @var string
     * @ORM\Column(name="first_name", type="string", length=30, nullable=true)
     * @Serializer\Groups({"UserList", "UserDetail"})
     */
    protected $firstName;

    /**
     * @var string
     * @ORM\Column(name="last_name", type="string", length=30, nullable=true)
     * @Serializer\Groups({"UserList", "UserDetail"})
     */
    protected $lastName;

    /**
     * @var string
     * @ORM\Column(name="phone", type="string", length=15, nullable=true)
     * @Serializer\Groups({"UserList", "UserDetail"})
     */
    protected $phone;

    /**
     * @var Address
     * @ORM\OneToOne(targetEntity="CoreBundle\Doctrine\Entity\Core\Address", cascade={"persist"})
     * @ORM\JoinColumn(name="address_id", referencedColumnName="id", nullable=true)
     * @Assert\Valid()
     * @Serializer\Groups({"AddressList", "AddressDetail"})
     */
    protected $address;

    /**
     * @var string
     * @ORM\Column(name="password_token", type="string", length=180, nullable=true)
     */
    protected $passwordToken;

    /**
     * Get first name
     * @return string
     */
    public function getFirstName()
    {
        return $this->firstName;
    }

    /**
     * Set first name
     * @param string $firstName
     */
    public function setFirstName($firstName)
    {
        $this->firstName = $firstName;
    }

    /**
     * Get last name
     * @return string
     */
    public function getLastName()
    {
        return $this->lastName;
    }

    /**
     * Set last name
     * @param string $lastName
     */
    public function setLastName($lastName)
    {
        $this->lastName = $lastName;
    }

    /**
     * Get phone
     * @return string
     */
    public function getPhone()
    {
        return $this->phone;
    }

    /**
     * Set phone
     * @param string $phone
     */
    public function setPhone($phone)
    {
        $this->phone = $phone;
    }

    /**
     * Get address
     * @return Address
     */
    public function getAddress()
    {
        return $this->address;
    }

    /**
     * Set address
     * @param Address $address
     */
    public function setAddress($address)
    {
        $this->address = $address;
    }

    /**
     * @return string
     */
    public function getEmail()
    {
        return $this->email;
    }

    /**
     * @param string $email
     */
    public function setEmail( $email)
    {
        $this->email = $email;
    }

    /**
     * @return string
     */
    public function getPasswordToken()
    {
        return $this->passwordToken;
    }

    /**
     * @param string $passwordToken
     */
    public function setPasswordToken(string $passwordToken = null)
    {
        $this->passwordToken = $passwordToken;
    }

}

Pouvez-vous m'aider s'il vous plaît

Aucune réponse