I'm developing a website with Symfony2 which contains an API to access datas from the mobile app. I use FOSUserBundle for authentication on website, FOSRestBundle & FOSOAuthServerBundle for the API.
I followed the tutorials on http://blog.tankist.de/blog/2013/07/17/oauth2-explained-part-2-setting-up-oauth2-with-symfony2-using-fosoauthserverbundle/ to implement the bundle.
I use password as grant_type so I can log in to the API using the user's login/password combination. I successfully get an access_token from the bundle but when I try to access api with this token (e.g. /api/user?access_token=MY_TOKEN
) I'm always being redirected to my website home page (which is my login page). I really don't know where I missed something.
Here is my configuration:
#app/Resources/config.yml
fos_oauth_server:
db_driver: orm
client_class: Cubbyhole\ApiBundle\Entity\Client
access_token_class: Cubbyhole\ApiBundle\Entity\AccessToken
refresh_token_class: Cubbyhole\ApiBundle\Entity\RefreshToken
auth_code_class: Cubbyhole\ApiBundle\Entity\AuthCode
service:
user_provider: fos_user.user_manager
#app/Resources/security.yml
#Firewalls for OAuth2
oauth_token:
pattern: ^/oauth/v2/token
security: false
oauth_authorize:
pattern: ^/oauth/v2/auth
form_login:
provider: fos_userbundle
check_path: fos_user_security_check
login_path: fos_user_security_login
anonymous: true
api:
pattern: ^/api
fos_oauth: true
stateless: true
access_control:
- { path: ^/api/oauth/v2, roles: [ IS_AUTHENTICATED_FULLY, IS_AUTHENTICATED_ANONYMOUSLY ] }
- { path: ^/api, roles: [ IS_AUTHENTICATED_FULLY ] }