I need help to understand how to secure an API.
I am working on a project based on a RESTful API with a JSON response.
I have a web application and a mobile application which send requests like this:
http://my-server.com/api/v1/products
with a protocol (GET, POST, PUT, and DELETE) and eventually parameters.
My concern is to secure these calls, from both applications. Today I am just checking if this is an Ajax call:
$method = $_SERVER['REQUEST_METHOD'];
if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest')
{
if ($method == 'GET')
{
return $data = $this->stores_model->get_all($select);
}
}
But mobile does not send xmlhttprequest, right?
I think I have to check a token stored in the session or locally for the mobile. I have also seen some points about the CSRF token, regenerate each time.
This is all I know about security. How do I get to understand more regarding my architecture?