gpt4 book ai didi

Symfony FOSOAuthServerBundle : access token not detected

转载 作者:行者123 更新时间:2023-12-02 15:18:32 25 4
gpt4 key购买 nike

我使用 FOSOAuthServerBundle 作为我的 oauth 端点。我使用资源所有者密码凭据授予方法成功生成了 token :

{
"access_token": "MY-FOO-TOKEN",
"expires_in": ​3600,
"token_type": "bearer",
"scope": "read",
"refresh_token": "MY-BAR-REFRESH-TOKEN"
}

现在我想用它来获取一些 protected 资源。所以我这样做了:

curl -X GET -H "Authorization: Bearer MY-FOO-TOKEN" "http://localhost:8000/api/a-bar-resource"

似乎没有检测到持有者。

<小时/>

信息:

echo $this->get('security.token_storage')->getToken(); 给出:AnonymousToken(user="anon.",authentiated=true,roles="")

标题中有:

["authorization"]=> /** <-- Is the lowercase OK? **/
array(1) {
[0]=>
string(93) "Bearer MY-FOO-TOKEN"
}

我还尝试将 access_token 作为查询参数传递,但没有成功。

现在我猜测 config.ymlsecurity.yml 有问题。以下是一些精选部分:

config.yml:

fos_oauth_server:
[...]
service:
options:
supported_scopes: read
user_provider: fos_user.user_provider.username_email

安全.yml:

security:
[...]
firewalls:
api:
pattern: ^/api
fos_oauth: true
stateless: true
anonymous: false
access_control:
- { path: ^/api, roles: [ IS_AUTHENTICATED_ANONYMOUSLY ] }

最佳答案

我终于找到了问题的根源。由于相同的模式,我有一个防火墙使另一个防火墙无效:

security:
[...]
firewalls:
other_firewall: #this one
pattern: ^/
anonymous: true
api:
pattern: ^/api
fos_oauth: true
stateless: true
anonymous: true

我还认为,在一个防火墙中进行的身份验证在另一个防火墙中不可用,因此将防火墙的数量减少到严格的最低限度(一个不安全,一个具有身份验证等)是一种很好的做法。然后使用 access_control 进行精细访问。

关于Symfony FOSOAuthServerBundle : access token not detected,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33682995/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com