api-平台中基于会话的身份验证
Session based authentication in api-platform
我正在尝试设置基于会话的身份验证而不是我当前使用的 JWT,因为我不想将 JWT 令牌存储在本地存储中。
我已经使用本指南成功验证了自己 https://symfony.com/doc/current/security/json_login_setup.html 并获得了有关用户的响应数据。
但是对任何端点的进一步请求我得到 401 未经授权。
这是我的安全 yaml
security:
encoders:
App\Entity\User:
algorithm: bcrypt
providers:
app_user_provider:
entity:
class: App\Entity\User
property: email
firewalls:
dev:
pattern: ^/_(profiler|wdt)
security: false
api:
pattern: ^/api/
stateless: true
anonymous: true
provider: app_user_provider
json_login:
check_path: /api/login
username_path: email
password_path: password
#success_handler: lexik_jwt_authentication.handler.authentication_success
#failure_handler: lexik_jwt_authentication.handler.authentication_failure
#guard:
# authenticators:
# - lexik_jwt_authentication.jwt_token_authenticator
main:
anonymous: true
access_control:
- { path: ^/api/authentication_token, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/api/graphql, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/api/form/, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/api/, roles: IS_AUTHENTICATED_FULLY }
- { path: ^/, roles: IS_AUTHENTICATED_ANONYMOUSLY }
在官方 api 平台文档中,没有提到使用基于会话的登录,我觉得这很奇怪。
谢谢
您需要删除 stateless: true
或将其更改为 stateless: false
The stateless
configuration parameter prevents Symfony from trying to
store the authentication information in the session
我觉得其他一切都不错,但是如果这不能解决您的问题,您可以将任何返回的消息与 401
响应代码一起添加到您的问题吗?
我正在尝试设置基于会话的身份验证而不是我当前使用的 JWT,因为我不想将 JWT 令牌存储在本地存储中。
我已经使用本指南成功验证了自己 https://symfony.com/doc/current/security/json_login_setup.html 并获得了有关用户的响应数据。
但是对任何端点的进一步请求我得到 401 未经授权。
这是我的安全 yaml
security:
encoders:
App\Entity\User:
algorithm: bcrypt
providers:
app_user_provider:
entity:
class: App\Entity\User
property: email
firewalls:
dev:
pattern: ^/_(profiler|wdt)
security: false
api:
pattern: ^/api/
stateless: true
anonymous: true
provider: app_user_provider
json_login:
check_path: /api/login
username_path: email
password_path: password
#success_handler: lexik_jwt_authentication.handler.authentication_success
#failure_handler: lexik_jwt_authentication.handler.authentication_failure
#guard:
# authenticators:
# - lexik_jwt_authentication.jwt_token_authenticator
main:
anonymous: true
access_control:
- { path: ^/api/authentication_token, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/api/graphql, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/api/form/, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/api/, roles: IS_AUTHENTICATED_FULLY }
- { path: ^/, roles: IS_AUTHENTICATED_ANONYMOUSLY }
在官方 api 平台文档中,没有提到使用基于会话的登录,我觉得这很奇怪。
谢谢
您需要删除 stateless: true
或将其更改为 stateless: false
The
stateless
configuration parameter prevents Symfony from trying to store the authentication information in the session
我觉得其他一切都不错,但是如果这不能解决您的问题,您可以将任何返回的消息与 401
响应代码一起添加到您的问题吗?