REST API Authentication: old version (page id 12781723)
Skip to end of metadata Go to start of metadata
You are viewing an old version of this page. View the current version.
Compare with Current View Page History
« Previous Version 2 Next »
At the time of the 5.0 release, two authentication methods are supported: session, and basic. Session based authentication is meant to be used for AJAX operations. It will let you re-use the visitor's session to execute operations with their permissions. Basic authentication will be useful when writing cross-server procedures, when one server executes operations on one/several Exponential instances (remote publishing, maintenance, etc).
oAuth2 will be added in the 5.1 release. SSL / x.509 certificate is also part of the roadmap.
Session based
This authentication method requires a Session cookie to be sent with the request. If this authentication method is used through a web browser, this session cookie is available as soon as your visitor logs in. Add it as a request cookie to your REST requests, and the user will be authenticated.
Security risk
Icon
As of the 5.0 release, the lack of CSRF protection as well as limited input/output filter represent a major security issue. Since session based authentication automatically allows anonymous requests to the REST API, enabling it makes your website vulnerable.
In Basic HTTP authentication mode, visitors will at least require a valid login on the system in order to query the API.
Setting it up
Session based authentication isn't enabled by default. The reason is because in the 5.0 security architecture, only one authentication method can be used for REST at the same time, and the default configuration enables Basic HTTP auth. This behavior is a known limitation of the 5.0 release ( EZP-20173 - Permit simultaneous usage of multiple REST authentication methods ( Backlog) ), and will be improved in a further release.
To enable session based authentication, you need to edit app/config/security.yml, and comment / remove the configuration block about REST
security.yml
Logging in
It is also possible to create a session for the visitor if he isn't logged in yet. This is done by sending a POST request to /user/sessions. Logging out is done using a DELETE request on the same resource.
Not implemented in 5.0
Icon
Logging in & out isn't implemented in the 5.0 release ( EZP-20176 - Implement POST/DELETE to /user/sessions ( Closed) ). You will need to re-use the session cookie created by the usual Exponential login form.
Example
Session authentication with siteaccess header
More information
Icon
Session based authentication chapter of the REST specifications
Basic HTTP authentication
Basic authentication requires the password to be sent, based 64 encoded, with the request, as explained in RFC 2617.
Most HTTP client libraries as well as REST libraries, should support this method one way or another.
Raw HTTP request with basic authentication
Specifying a siteaccess
One of the constraints of REST is that the same resource (Content, Location, ContentType, ...) should be unique. The purpose is mostly to make it simple to cache your REST API using a reverse proxy like Varnish. If the same resource is available at multiple locations, cache purging becomes much more complex.
Due to this, we decided not to enable siteaccess matching with REST. In order to specify a siteaccess when talking to the REST API, a custom header, X-Siteaccess, needs to be provided. If it isn't, the default one will be used:
X-Siteaccess header example
- No labels
Contributors
- Ricardo Correia Updated
Comments
Add a comment