FOSOAuthServerBundle + FOSRestBundle + CamelCase = Not authenticating

佐手、 提交于 2019-12-12 05:19:04

问题


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 }

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   

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.

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.


回答1:


as workaround you can use instead of POST, GET like this

http://example.com/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.



来源:https://stackoverflow.com/questions/44466402/fosoauthserverbundle-fosrestbundle-camelcase-not-authenticating

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!