Symfony does not authenticate users
I have a Symfony 2.8 web application executed as an API with a FosUserBundle for custom objects and a Fosoauthserver for authentication.
My security.yml:
security:
encoders:
FOS\UserBundle\Model\UserInterface: bcrypt
role_hierarchy:
ROLE_ADMIN: [ROLE_USER, ROLE_ALLOWED_TO_SWITCH]
ROLE_SUPER_ADMIN: ROLE_ADMIN
providers:
fos_userbundle:
id: fos_user.user_provider.username_email
firewalls:
oauth_token:
pattern: ^/oauth/v2/token
security: false
oauth_authorize:
pattern: ^/oauth/v2/auth
form_login:
provider: fos_userbundle
check_path: /oauth/v2/auth_login_check
login_path: /oauth/v2/auth_login
anonymous: true
api:
pattern: ^/v1
fos_oauth: true
stateless: true
switch_user_stateless: true
anonymous: false
access_control:
- { path: ^/v1/register, role: IS_AUTHENTICAIS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/v1/login, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/v1, role: IS_AUTHENTICATED_FULLY }
I can register user and login by getting access_token correctly, but when I try to access any endpoint of my API, I can access without login.
Even though I have set the correct access token in the headers, if I do $ this-> getUser (), I get null because my app is authenticating at any time.
Any idea? I made different APIs and I didn't have this problem. Thank!
+3
source to share
No one has answered this question yet
Check out similar questions: