1

Is it possible to login by sending GET/POST request? I'm trying to login from mobile app. So I want to somehow post username and password to php.

This is how I have it right now: http://symfony.com/doc/current/security/form_login_setup.html

EDIT:

I tought this could help, but it is logging in without password or with wrong password, so I think it's not what I need?

$token = new UsernamePasswordToken($user, 'password', 'main', $user->getRoles());
$this->get('security.token_storage')->setToken($token);

Thanks

DonCallisto
  • 29,419
  • 9
  • 72
  • 100

2 Answers2

1

I think the best options are:

  1. Use basic http authentication. By passing the user credentials to http header formated as base64.
  2. Perform a post to auth and return a token on success then use this token to perform actions. In that case is recommended on each action to renew the token and keep token related info in the database such as: ip, time, user_id, and infomation that if the token is used or not.
Dimitrios Desyllas
  • 9,082
  • 15
  • 74
  • 164
1

You are very close to the solution, you'll need to dispatch an InteractiveLoginEvent event to authenticate programmatically. See:

symfony2 programmatically authenticate user

How to programmatically login/authenticate a user?

Community
  • 1
  • 1
jkrnak
  • 956
  • 6
  • 9