I’m trying to authenticate a user on my symfony2 server.
The authentication works with curl in cli :
curl "http://localhost:8080/app_dev.php/app/user/profile.json?id=4" -u foo:bar --basic
But with Android i always get a 401 error with this error:
A Token was not found in the SecurityContext.
What can I do to fix it ?
Here is my security.yml:
security:
providers:
fos_userbundle:
id: fos_user.user_manager
encoders:
BumpMe\UserBundle\Entity\User: sha512
firewalls:
app:
pattern: ^/app/.*
stateless: true
security: true
http_basic:
realm: "API"
main:
pattern: ^/
form_login:
provider: fos_userbundle
logout: true
anonymous: true
access_control:
- { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/admin/, role: ROLE_ADMIN }
- { path: ^/app/, role: ROLE_USER }
role_hierarchy:
ROLE_ADMIN: ROLE_USER
ROLE_SUPER_ADMIN: ROLE_ADMIN
Also, how can i send the username and the password in base64 ? Because currently on Android it doesn’t want the base64 and curl sent it on base64…
I don’t understand this error…
Sorry i find out…
It’s just because Symfony wanted a base64 encoded.
The base64 encoding didn’t work on Android because, the method add a new line after the encoded datas so, it’s not the same…
With a simple trim it’s fine :
I think it can be helpful.