我已经使用 JWT 令牌向 ElasticBeanstalk 部署了一个 API-Platform 应用程序,它像往常一样在我的本地服务器上运行良好。
在 EB 上,尽管BearerToken提供了正确的信息,但它拒绝访问已登录的用户。
这是抛出的错误:
{
"errors": [
{
"message": "Access Denied.",
"extensions": {
"category": "graphql"
},
"locations": [
{
"line": 6,
"column": 9
}
],
"path": [
"retrievedQueryUser"
]
}
],
"data": {
"retrievedQueryUser": null
}
}
有问题的查询尝试通过以下graphql配置检索用户配置文件信息:
* "retrievedQuery"={
* "item_query"=UserProfileResolver::class,
* "normalization_context"={"groups"={"get-owner"}},
* "security"="is_granted('IS_AUTHENTICATED_FULLY') and object == user"
* },
IS_AUTHENTICATED_FULLY因此,检查用户是否以及是否是他/她自己试图执行查询应该是一件简单的事情。
据我所知,通过在下方转储/vendor/symfony/security-core/Authorization/AuthorizationChecker.php,它无法检索令牌。
var_dump($this->tokenStorage->getToken()->getUser()->getUsername());
我粗略地比较了phpinfo()我的本地安装和 AWS-EB 上的安装,没有发现任何明显的不匹配。
这是 JWT 的配置/config/packages/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)%'
user_identity_field: email
token_ttl: 1800
只是为了确认用户能够登录。它正在通过isGranted()失败的检查。
有任何想法吗?
编辑 - 添加`/config/packages/security.yaml
security:
# https://symfony.com/doc/current/security.html#where-do-users-come-from-user-providers
encoders:
App\Entity\User:
algorithm: auto
#algorithm: bcrypt
#algorithm: argon2i
cost: 12
providers:
database:
entity:
class: App\Entity\User
property: email
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
refresh:
pattern: ^/api/token/refresh
stateless: true
anonymous: true
api:
pattern: ^/api
stateless: true
anonymous: true
json_login:
check_path: /api/login_check
success_handler: lexik_jwt_authentication.handler.authentication_success
failure_handler: lexik_jwt_authentication.handler.authentication_failure
guard:
authenticators:
- app.google_login_authenticator
- App\Security\TokenAuthenticator
entry_point: App\Security\TokenAuthenticator
user_checker: App\Security\UserEnabledChecker
access_control:
- { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/admin, roles: ROLE_SUPERADMIN }
- { path: ^/api/token/refresh, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/api, roles: IS_AUTHENTICATED_ANONYMOUSLY }
role_hierarchy:
ROLE_PROVIDER: ROLE_USER
ROLE_ADMIN: [ROLE_PROVIDER, ROLE_EDITOR]
ROLE_SUPERADMIN: ROLE_ADMIN