我正在尝试使用记录的设置来设置API平台:
https://api-platform.com/docs/core/jwt/
我已按以下方式加载灯具:
#src/DataFixtures/AppFixtures.php
private function loadUsers(ObjectManager $manager)
{
$users = $this->getUserData();
foreach ($users as $user) {
$_user = new User();
$_user->setUsername($user['username']);
$_user->setPassword($user['password']);
$_user->setEmail($user['email']);
$_user->setPassword($this->passwordEncoder->encodePassword($_user, $user['password']));
$manager->persist($_user);
}
$manager->flush();
}
private function getUserData()
{
$users = array(
['first_name'=>'John','last_name'=>'Doe','username'=>'johndoe','email'=>'johndoe@gmail.com','password'=>'test'],
return $users;
}
我的security.yml看起来像这样:
security:
encoders:
App\Entity\User:
algorithm: bcrypt
role_hierarchy:
ROLE_READER: ROLE_USER
ROLE_ADMIN: ROLE_READER
providers:
jwt_user_provider:
entity:
class: App\Entity\User
firewalls:
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
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
access_control:
- { path: ^/api/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/api, roles: IS_AUTHENTICATED_FULLY }
现在我想尝试获取一个令牌:
curl -X POST http://localhost:8000/api/login_check -d _username=johndoe -d _password=test
但我得到了非json的回应。在某处我找到了这条消息:
my-imac:project-folder measauser$ curl -X POST http://localhost:8000/api/login_check -d _username=johndoe@gmail.com -d _password=test
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<meta name="robots" content="noindex,nofollow" />
<meta name="viewport" content="width=device-width,initial-scale=1" />
<title> Failed to load private key "/Users/measauser/Sites/project-folder/config/jwt/private.pem":
06065064:digital envelope routines:EVP_DecryptFinal_ex:bad decrypt
0906A065:PEM routines:PEM_do_header:bad decrypt (500 Internal Server Error)
这是我的.env文件:
###> lexik/jwt-authentication-bundle ###
# Key paths should be relative to the project directory
JWT_PRIVATE_KEY_PATH=config/jwt/private.pem
JWT_PUBLIC_KEY_PATH=config/jwt/public.pem
JWT_PASSPHRASE=42761e3ad1eb66faf082ac0763e46a2d
###< lexik/jwt-authentication-bundle ###
1)为什么这条消息实际上不在json中?
2)为什么会发生这种错误?
3)我也无法访问文档,因为我找到了消息{&#34; code&#34;:401,&#34; message&#34;:&#34; JWT Token not found&#34;}在浏览器中
有人可以帮帮我吗?
更新 2)似乎.env中的JWT_PASSPHRASE没有正确匹配我键入的密码。所以这部分已经解决了。