我一直在 Symfony 2.8 中处理我的服务器,构建了一个以驼峰式风格返回 json 对象的 rest api,现在的问题是,当我集成 OauthServer 包时,它会出现此错误 无效的 grant_type 参数或参数丢失",我知道发生这种情况是因为我在我的 fos_rest 配置中使用了 array_normalizer: fos_rest.normalizer.camel_keys 主体侦听器.这是我在 configuration.yml:
I have been working on my server in Symfony 2.8, building a rest api which returns json objects in camelCase style, the problem now is that when I integrate the OauthServer bundle it lauches this error Invalid grant_type parameter or parameter missing", I understand that this happens because I am using the array_normalizer: fos_rest.normalizer.camel_keys body listener in my fos_rest configuration. Here my code in configuration.yml:
fos_rest: #other listeners# body_listener: array_normalizer: fos_rest.normalizer.camel_keys zone: - { path: ^/api }这里是我在 security.yml 中的 Oauth 配置:
And here my Oauth configuration in the security.yml:
firewalls: oauth_token: pattern: ^/oauth/v2/token security: false api: pattern: ^/api fos_oauth: true stateless: true anonymous: false我发现我不是第一个发生这种情况的人,并且添加了 zone 属性来缓解这种情况,但在我的情况下,它仅适用于 下的所有内容^/api 因为当我更改模式时,它会按预期停止使用侦听器,但是当我调用 ^/oauth/v2/token 路径时,它似乎忽略了 zone 给定路径.
I found out I was not the first person who this ever happened, and that the zone attribute was added to mitigate this, but in my case it does work only with everything under the ^/api because when I change the pattern it stops using the listeners as expected but when I call the ^/oauth/v2/token path it seems to ignore the zone given path.
要检索我的令牌,我正在使用下一个 POST 请求:
To retrieve my token, I am using the next POST request:
{ grant_type= "password" client_id= "clientId" client_secret= "clientSecret" username= "user" password= "password" }我想澄清一下,如果我停用侦听器,我将成功获得令牌,但我的应用程序的其余部分停止工作,因为它到处都使用驼峰命名法,我知道一旦选择将在客户端序列化我的数据,但是目前情况相当复杂.
I want to clarify that if I deactivate the listener I obtain the token successfully, but the rest of my app stops working because it uses camelCase everywhere, I know that once alternative would be to serialize my data in the client side, but it is quite complicated at the moment.
我做错了什么?我不知道我错过了什么.
What am I doing wrong? I can't figure out what I am missing.
推荐答案作为解决方法,您可以使用这样的 POST、GET 来代替
as workaround you can use instead of POST, GET like this
example/oauth/v2/token?client_id=[CLIENT_ID]&client_secret=[SECRET]&grant_type=password&username=[USERNAME]&password=[PASSWORD]那么你就不必担心正文序列化器了.
Then you don`t have to worry about body serializers.
更多推荐
FOSOAuthServerBundle + FOSRestBundle + CamelCase = 未认证
发布评论