简体   繁体   中英

FOSOAuthServerBundle + FOSRestBundle + CamelCase = Not authenticating

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM