Я пытаюсь создать аутентификацию JWT с помощью LexikJWTAuthenticationBundle.
На http://127.0.0.1:8000/api/
и http://127.0.0.1:8000/api/login_check?username=****&password=****
я получаю
{
"code": 401,
"message": "Bad credentials"
}
в качестве ответа.
Мой security.yaml выглядит следующим образом:
security:
encoders:
FOS\UserBundle\Model\UserInterface: sha512
App\Entity\User:
algorithm: bcrypt
providers:
my_provider:
entity:
class: App\Entity\User
property: username
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
login:
pattern: ^/backend/api/login
stateless: true
form_login:
check_path: /backend/api/login_check
username_parameter: _username
password_parameter: _password
success_handler: lexik_jwt_authentication.handler.authentication_success
failure_handler: lexik_jwt_authentication.handler.authentication_failure
require_previous_session: false
guard:
authenticators:
- App\Security\LoginFormAuthenticator
api:
pattern: ^/api
stateless: true
lexik_jwt: ~
guard:
authenticators:
- lexik_jwt_authentication.jwt_token_authenticator
access_control:
- { path: ^/api/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/api, roles: IS_AUTHENTICATED_FULLY }
rout.yaml :
api_login_check:
path: api/login_check
lexik_jwt_authentication.yaml :
lexik_jwt_authentication:
secret_key: '%kernel.project_dir%/config/jwt/private.pem' # required for token creation
public_key: '%kernel.project_dir%/config/jwt/public.pem' # required for token verification
pass_phrase: 'pass' # required for token creation, usage of an environment variable is recommended
token_ttl: 86400
Файл Entity / User.php :
<?php
namespace App\Entity;
use ApiPlatform\Core\Annotation\ApiResource;
use Doctrine\ORM\Mapping as ORM;
use FOS\UserBundle\Model\User as BaseUser;
use Symfony\Component\Security\Core\User\UserInterface;
/**
* @ApiResource()
* @ORM\Table(name="user")
* @ORM\Entity(repositoryClass="App\Repository\UserRepository")
*/
class User implements UserInterface, \Serializable
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
*/
private $username;
/**
* @ORM\Column(type="string", length=255)
*/
private $fullname;
/**
* @ORM\Column(type="string", length=255)
*/
private $password;
/**
* @ORM\Column(type="string", length=255)
*/
private $email;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $mobile;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $bild;
/**
* @ORM\Column(type="boolean")
*/
private $status;
/**
* @ORM\Column(type="integer")
*/
private $usergroupid;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $activewidgetid;
public function getId(): ?int
{
return $this->id;
}
public function getUsername(): ?string
{
return $this->username;
}
public function setUsername(string $username): self
{
$this->username = $username;
return $this;
}
public function getFullname(): ?string
{
return $this->fullname;
}
public function setFullname(string $fullname): self
{
$this->fullname = $fullname;
return $this;
}
public function getPassword(): ?string
{
return $this->password;
}
public function setPassword(string $password): self
{
$this->password = $password;
return $this;
}
public function getEmail(): ?string
{
return $this->email;
}
public function setEmail(string $email): self
{
$this->email = $email;
return $this;
}
public function getMobile(): ?string
{
return $this->mobile;
}
public function setMobile(?string $mobile): self
{
$this->mobile = $mobile;
return $this;
}
public function getBild(): ?string
{
return $this->bild;
}
public function setBild(?string $bild): self
{
$this->bild = $bild;
return $this;
}
public function getStatus(): ?bool
{
return $this->status;
}
public function setStatus(bool $status): self
{
$this->status = $status;
return $this;
}
public function setEnabled(bool $enabled): self
{
$this->enabled = $enabled;
return $this;
}
public function setSuperAdmin(bool $enabled): self
{
$this->enabled = $enabled;
return $this;
}
public function getUsergroupid(): ?int
{
return $this->usergroupid;
}
public function setUsergroupid(int $usergroupid): self
{
$this->usergroupid = $usergroupid;
return $this;
}
public function getActivewidgetid(): ?string
{
return $this->activewidgetid;
}
public function setActivewidgetid(?string $activewidgetid): self
{
$this->activewidgetid = $activewidgetid;
return $this;
}
public function getRoles()
{
return array('ROLE_ADMIN');
}
public function getSalt() {}
public function eraseCredentials() {}
public function serialize()
{
return serialize([
$this->id,
$this->username,
$this->password,
$this->email
]);
}
public function unserialize($string)
{
list (
$this->id,
$this->username,
$this->password,
$this->email
) = unserialize($string, ['allowed_classes' => false]);
}
}
У меня даже нет доступа даже к Swagger, мой api_platfrom.yaml выглядит так:
# api/config/packages/api_platform.yaml
api_platform:
swagger:
api_keys:
apiKey:
name: Authorization
type: header
Также созданы ключи:
Есть предложения, решение?Заранее спасибо