api - 401 错误凭据 [lexik/JWTBundle]
问题描述
我正在构建一个 API。当我创建一个用户时,我会收到一个令牌。但是,当我更改用户信息时,无法重新连接,并且收到带有错误凭据消息的 401 错误代码。请问怎么解决这个问题?
我使用 FOSRestBundle、lexikJWTAuthenticator 和 NelmioCORSBundle
# security.yaml
security:
encoders:
App\Entity\User:
algorithm: argon2i
# https://symfony.com/doc/current/security.html#where-do-users-come-from-user-providers
providers:
# used to reload user from session & other features (e.g. switch_user)
app_user_provider:
entity:
class: App\Entity\User
property: email
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
signup:
pattern: ^/api/signup
stateless: true
anonymous: true
signin:
pattern: ^/api/signin
stateless: true
anonymous: true
json_login:
check_path: /api/signin
success_handler: lexik_jwt_authentication.handler.authentication_success
failure_handler: lexik_jwt_authentication.handler.authentication_failure
api:
pattern: ^/api
stateless: true
guard:
authenticators:
- lexik_jwt_authentication.jwt_token_authenticator
main:
anonymous: true
# activate different ways to authenticate
# https://symfony.com/doc/current/security.html#firewalls-authentication
# https://symfony.com/doc/current/security/impersonating_user.html
# switch_user: true
role_hierarchy:
ROLE_ADMIN: ROLE_USER
# Easy way to control access for large sections of your site
# Note: Only the *first* access control that matches will be used
access_control:
- { path: ^/api/signin, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/api/signup, roles: IS_AUTHENTICATED_ANONYMOUSLY }
# - { path: ^/api, roles: IS_AUTHENTICATED_ANONYMOUSLY, methods: GET }
# - { path: ^/api, roles: IS_AUTHENTICATED_FULLY, methods: [PUT, DELETE, POST] }
# - { path: ^/admin, roles: ROLE_ADMIN }
# - { path: ^/profile, roles: ROLE_USER }
# lexik_jwt_authentication.yaml
lexik_jwt_authentication:
secret_key: '%env(resolve:JWT_SECRET_KEY)%'
public_key: '%env(resolve:JWT_PUBLIC_KEY)%'
pass_phrase: '%env(JWT_PASSPHRASE)%'
token_ttl: 3600
谢谢
解决方案
推荐阅读
- python - 在 django 中找不到模板 url
- javascript - 使用简单的 JavaScript 函数隐藏 div 元素的问题
- python - 列出当前登录用户的对象
- docker - 在 docker-selenium 中测试可以在本地运行但不能在 Jenkins 上下载文件
- c++ - 使用模板类构建基于 CMake 的项目的正确方法
- javascript - 如何阻止 Javascript 菜单下划线进入下拉框?
- javascript - 如何根据 Axios 承诺中的代码从函数返回不同的值?NodeJS - 一个
- r - GGplot 与规格
- webpack - 我的 gulp 文件不会读取任何更改,但它运行时问题为零
- java - 如何找到按键的KeyCode