I have a basic api that authenticates users using FOSOAuthServerBundle. Users can have the roles ROLE_USER and ROLE_ADMIN. Based on the FOSOAuthServerBundle docs, the default behavior is to use scopes as roles, so I thought that when I have a regular user, the package will return scope: user in response, and when it becomes an administrator user, scope: admin will return. But this is not so. The package returns everything that is configured in the supported_scopes entry. Below is my config.yml .
fos_oauth_server: service: options: supported_scopes: user admin
My access_control section in security.yml empty, and my firewalls section is below:
firewalls: users_create: pattern: ^/v1/users methods: [POST] security: false api: pattern: ^/ security: true fos_oauth: true stateless: true access_control: # You can omit this if /api can be accessed both authenticated and anonymously
Thus, the bundle always returns user admin as the scope even if the user does not have the ROLE_ADMIN role.
{ "access_token": "ZGQ2ODE5ZjAzNTZkOWY0OWMyNmZmODE4MjcwZTJmYjExNzY0NzQxOTRmMzk4NzA2Mjc2NjIyZmY1ZDgwMzk4NA" "expires_in": 3600 "token_type": "bearer" "scope": "user admin" "refresh_token": "NmM5ZGFmNzBiNTNjYmQzMTQ1MTk0ODJjOTAxMWU0YWIwMzM1MzgyODg4ZTAzNTI5ZTk2MDc3OGU2MTg0MWZiMA" }
What am I missing? Isn't the user role associated with the token scope? Is there a better way to find out if my user is an administrator or not?
source share