Symfony2 basic http auth, works with curling, but not on Android

I am trying to authenticate a user on my symfony2 server. 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 error 401 with this error:

  A Token was not found in the SecurityContext. 

What can I do to fix this?

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 username and password in base64? Since currently on Android, he doesn't want base64 and curl to send it to base64 ...

I do not understand this error ...

+4
source share
1 answer

Sorry to find out ...

This is simply because Symfony wanted to encode base64. Base64 encoding did not work on Android, because the method adds a new line after the encoded data, so this is not the same ...

With a simple finish, this is normal:

 "Basic "+Base64.encodeToString((login+":"+pass).getBytes(), Base64.DEFAULT).trim(); 

I think this may be helpful.

+2
source

Source: https://habr.com/ru/post/1393625/


All Articles