Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/symfony/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Symfony4+;jwt auth RECASPE始终返回{quot;code";:401,“message";:“错误凭据”}_Php_Symfony_Jwt_Lexikjwtauthbundle - Fatal编程技术网

Php Symfony4+;jwt auth RECASPE始终返回{quot;code";:401,“message";:“错误凭据”}

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

我有一个Symfony4安装,其中使用Flex安装了几个常见的捆绑包

  • 制造
  • 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);