Я столкнулся с проблемой с пакетом JWT Auth на Symfony 3. Я следил за инструкциями из их github README, но просто не могу понять, где я поступил неправильно или что идет не так.Symfony LexikJWTAuthenticationBundle Не удалось выполнить проверку подлинности
Я использую Symfony 3.1.1, с LexikJWTAuthenticationBundle 2.0 И FriendsofSymfony userbundle.
Проблема: Всякий раз, когда я пытаюсь войти в систему, как указано в их примере с помощью (с пользователем и паролем подмененной):
curl -X POST http://192.168.33.30/api/login_check -d _username=johndoe -d _password=test
я получаю:
{"code":401,"message":"Bad credentials"}
Если я произвожу токен вручную через:
$jwtManager = $this->container->get('lexik_jwt_authentication.jwt_manager');
$userManager = $this->container->get('fos_user.user_manager');
$user = $userManager->findUserByEmail('emailhere');
dump($jwtManager->create($user));
Мне дают довольно длинный токен. И затем, используя это в почтовом ящике в качестве заголовка с ключом «Авторизация» значение: «Носитель»
Затем я пытаюсь вызвать конечную точку под брандмауэром и вызвать fail_handler. Ему удается извлечь из токена данные, то есть электронную почту, которую я закодировал в токене, и так далее. Но я всегда получаю неудачу.
Мои другие данные:
security.yml безопасности: кодеры: FOS \ UserBundle \ Model \: Bcrypt пользовательским интерфейсом
role_hierarchy:
ROLE_ADMIN: ROLE_USER
ROLE_SUPER_ADMIN: ROLE_ADMIN
# http://symfony.com/doc/current/book/security.html#where-do-users-come-from-user-providers
providers:
in_memory:
memory: ~
fos_userbundle:
id: fos_user.user_provider.username
firewalls:
# disables authentication for assets and the profiler, adapt it according to your needs
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
login:
pattern: ^/api/login
stateless: true
anonymous: true
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
guard:
authenticators:
- lexik_jwt_authentication.jwt_token_authenticator
main:
pattern: ^/
form_login:
provider: fos_userbundle
# csrf_token_generator: security.csrf.token_manager
logout: true
anonymous: true
config.yml
lexik_jwt_authentication:
private_key_path: %jwt_private_key_path%
public_key_path: %jwt_public_key_path%
pass_phrase: %jwt_key_pass_phrase%
token_ttl: %jwt_token_ttl%
# key under which the user identity will be stored in the token payload
user_identity_field: email
# token encoding/decoding settings
encoder:
# token encoder/decoder service - default implementation based on the namshi/jose library
service: lexik_jwt_authentication.encoder.default
# crypto engine used by the encoder service
crypto_engine: openssl
# encryption algorithm used by the encoder service
signature_algorithm: RS256
# token extraction settings
token_extractors:
authorization_header: # look for a token as Authorization Header
enabled: true
prefix: Bearer
name: Authorization
cookie: # check token in a cookie
enabled: false
name: BEARER
query_parameter: # check token in query string parameter
enabled: false
name: bearer
маршрутизации .yml
api_login_check:
path: /api/login_check
Если у кого-либо есть предложения, пожалуйста, дайте мне знать. Я преувеличиваю это.
работал отлично. Не знаю, почему там была конфигурация in_memory. Спасибо! – Greg