Php Symfony4+;jwt auth RECASPE始终返回{quot;code";:401,“message";:“错误凭据”}
我有一个Symfony4安装,其中使用Flex安装了几个常见的捆绑包Php Symfony4+;jwt auth RECASPE始终返回{quot;code";:401,“message";:“错误凭据”},php,symfony,jwt,lexikjwtauthbundle,Php,Symfony,Jwt,Lexikjwtauthbundle,我有一个Symfony4安装,其中使用Flex安装了几个常见的捆绑包 制造 jwt认证 注释 比哈特 菲普尼特 服务器 我有一个路由文件: api_login_check: path: /api/login_check 我有以下配置: security: encoders: App\Security\User: plaintext providers: app.provider: id: App\Secur
- 制造
- jwt认证
- 注释
- 比哈特
- 菲普尼特
- 服务器
api_login_check:
path: /api/login_check
我有以下配置:
security:
encoders:
App\Security\User: plaintext
providers:
app.provider:
id: App\Security\UserProvider
firewalls:
login:
pattern: ^/api/login
stateless: true
anonymous: true
provider: app.provider
form_login:
check_path: /api/login_check
success_handler: lexik_jwt_authentication.handler.authentication_success
failure_handler: lexik_jwt_authentication.handler.authentication_failure
require_previous_session: false
api:
pattern: ^/api
stateless: true
provider: app.provider
guard:
authenticators:
- lexik_jwt_authentication.jwt_token_authenticator
access_control:
- { path: ^/api/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/api, roles: IS_AUTHENTICATED_FULLY }
而这个用户:
<?php
namespace App\Security;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Security\Core\User\EquatableInterface;
class User implements UserInterface, EquatableInterface
{
private $username;
private $password;
private $salt;
private $roles;
public function __construct($username, $password, $salt, array $roles)
{
$this->username = $username;
$this->password = $password;
$this->salt = $salt;
$this->roles = $roles;
}
public function getRoles()
{
return $this->roles;
}
public function getPassword()
{
return $this->password;
}
public function getSalt()
{
return $this->salt;
}
public function getUsername()
{
return $this->username;
}
public function eraseCredentials()
{
}
public function isEqualTo(UserInterface $user)
{
if (!$user instanceof User) {
return false;
}
if ($this->password !== $user->getPassword()) {
return false;
}
if ($this->salt !== $user->getSalt()) {
return false;
}
if ($this->username !== $user->getUsername()) {
return false;
}
return true;
}
}
如果您使用明文密码编码器
并向用户
类提供salt
,则用户
的获取密码
方法应返回普通密码{salt}
在这种情况下,
$username = 'senso';
$password = 'rario{sale}';
$salt = 'sale';
$roles = ['ROLE_ADMIN'];
return new User($username, $password, $salt, $roles);
或
可以使用。您能发布您尝试过的正确的curl
吗?我想检查:url是否正确(而不是http://localhost:800ogin_check
发布),选择的密码是rario
,而不是test
。您可以将提供商:app.provider
添加到登录
防火墙下吗?完成,仍然无法工作我假设您在路由器配置中注册了/api/login\u check
,您能确认吗?是的。我已经回答了这个问题
$username = 'senso';
$password = 'rario{sale}';
$salt = 'sale';
$roles = ['ROLE_ADMIN'];
return new User($username, $password, $salt, $roles);
$username = 'senso';
$password = 'rario';
$salt = '';
$roles = ['ROLE_ADMIN'];
return new User($username, $password, $salt, $roles);