I’m making an application and I need to authenticate users with a POST cUrl call:
$app = new Silex\Application();
$app->register(new Silex\Provider\SessionServiceProvider());
$app['debug'] = true;
$app->post('/api/auth/login', function (Request $request) use ($app) {
if ($request->get('username') === 'admin' && $request->get('password') === 'admin') {
return $app->json(array('sessionId' => $app['session']->getId()));
} else {
$error = array('message' => 'Authentication failed');
return $app->json($error, 404);
}
});
when I use:
curl -X POST -d username=admin -d password=admin http://app.local/api/auth/login
every time my application returns me a different session identifier!
PHP Code:
Curl command:
The above command will write a “cookie” file in the current working directory. Please check that the directory is writable or the user has the correct permissions.