FriendsOfSymfony / FOSOAuthServerBundle

A server side OAuth2 Bundle for Symfony
1.09k stars 450 forks source link

Using scope makes invalid grant_type #586

Closed noon974 closed 6 years ago

noon974 commented 6 years ago

Hi,

I'm trying to use supported_scopes up and running for my project. As soon as I add the supported_scopes field in my config.yml :

`fos_oauth_server:

db_driver: mongodb       
client_class:        oAuth\Client
refresh_token_class: oAuth\RefreshToken
auth_code_class:     oAuth\AuthCode
access_token_class:  oAuth\AccessToken
service:
    options:
        supported_scopes: user`

I'm getting this from Postman when requesting a token :

{"error":"unauthorized_client","error_description":"The grant type is unauthorized for this client_id"}

Here is the payload of the call made by Postman : { "grant_type": "client_credentials", "client_id": "myclientId", "client_secret": "mysecret", "scope": "user" }

If I remove the "supported_scopes" from config.yml and the scope from the post payload, I'll get my oauth token as expected.

So, I started digging into oauth2-php library and put some dump to see what's happening. When "suported_scopes" is set in config.yml, the ClientManager return : `Client {#612 ▼

id: "myId"

name: "BackOffice"

scope: array:2 [▶]

randomId: null

secret: null

redirectUris: []

allowedGrantTypes: []

}`

When config.yml doesn't contains the supported_scopes, I get : `Client {#2288 ▼

id: "myId"

name: "BackOffice"

scope: array:2 [▶]

randomId: "myrandomId"

secret: "mySecret"

redirectUris: []

allowedGrantTypes: array:1 [▶]

}`

It seems that the OAuthClient object is not well hydrated ... any clues of why this is happening ?

noon974 commented 6 years ago

Something were wrong with my config.yml (I'm using PHPStorm deployment feature when working locally on the source code). If I do the same changes on the server file, without deployment upload of PHPStorm, everything's fine.