I'm trying to create REST API application with token-based authentication. Calling
/ouath2/v2/token?client_id=CLIENT_ID&client_secret=CLIENT_SECRET&grant_type=client_credentials
returns access_token, it's ok.
However, when I'm trying to use it in the next api requests server raises exception with 'Full authentication is required to access this resource.' message. I tried several ways to use access_token: in the query (/api/action?access_token=ACCESS_TOKEN
), in the header (Authorization: Bearer ACCESS_TOKEN
) but all of them doesn't work.
Could you tell me what's wrong with my configuration?
part of my config.yml with FOSOAuthServerBundle && FOSUserBundle:
fos_user:
db_driver: orm
firewall_name: main
user_class: AppBundle\Entity\User
fos_oauth_server:
db_driver: orm
client_class: AppBundle\Entity\Client
access_token_class: AppBundle\Entity\AccessToken
refresh_token_class: AppBundle\Entity\RefreshToken
auth_code_class: AppBundle\Entity\AuthCode
service:
user_provider: testApp.user.provider
options:
supported_scopes: user
security.yml:
main:
anonymous: ~
oauth_token:
pattern: ^/oauth/v2/token
security: false
api:
pattern: ^/api
fos_oauth: true
stateless: true
anonymous: false # can be omitted as its default value
access_control:
- { path: ^/api, roles: [ IS_AUTHENTICATED_FULLY ] }