| 1 |
REST services |
| 2 |
============= |
| 3 |
|
| 4 |
LL::NG portal is a REST server that gives access to configuration, |
| 5 |
session and also authentication. |
| 6 |
|
| 7 |
Portal REST services |
| 8 |
-------------------- |
| 9 |
|
| 10 |
Authentication |
| 11 |
~~~~~~~~~~~~~~ |
| 12 |
|
| 13 |
The authentication service is always available with REST, you just need |
| 14 |
to send credentials on portal URL. But by default, the portal is |
| 15 |
protected by :ref:`one time tokens to prevent CSRF<security-portal>`. |
| 16 |
You must disable them or set a rule (configuration parameter |
| 17 |
``requireToken``) so token will not be required for REST requests, for |
| 18 |
example: |
| 19 |
|
| 20 |
.. code-block:: perl |
| 21 |
|
| 22 |
$env->{HTTP_ACCEPT} !~ m:application/json: |
| 23 |
|
| 24 |
|
| 25 |
Another solution is using the :doc:`REST auth/user/password backend<restauthuserpwdbackend>`. |
| 26 |
|
| 27 |
API |
| 28 |
^^^ |
| 29 |
|
| 30 |
Request parameters: |
| 31 |
|
| 32 |
- Endpoint: ``/`` |
| 33 |
- Method: ``POST`` |
| 34 |
- Request headers: |
| 35 |
|
| 36 |
- ``Accept``: ``application/json`` |
| 37 |
|
| 38 |
- POST data: |
| 39 |
|
| 40 |
- ``user``: user login |
| 41 |
- ``password``: user password |
| 42 |
- xxx: optional parameters, like ``lmAuth`` if your portal uses |
| 43 |
``Choice`` or ``spoofId`` to impersonate. |
| 44 |
|
| 45 |
The JSON response fields are: |
| 46 |
|
| 47 |
- ``result``: authentication result, ``0`` if it fails, ``1`` if it |
| 48 |
succeed |
| 49 |
- ``error``: error code, the corresponding error can be found in |
| 50 |
:doc:`Portal error codes<error_codes>` |
| 51 |
- ``id``: if authentication succeed, the session id is returned in this |
| 52 |
field. This id is not returned if you call the REST endpoint with the |
| 53 |
session cookie (which means you are already authenticated). |
| 54 |
|
| 55 |
|
| 56 |
.. tip:: |
| 57 |
|
| 58 |
You can also get the cookie by reading the response header |
| 59 |
``Cookie`` returned by the portal. |
| 60 |
|
| 61 |
|
| 62 |
.. attention:: |
| 63 |
|
| 64 |
Before version 2.0.4, the response to a success |
| 65 |
authentication had no ``id`` field, and ``error`` field was named |
| 66 |
``code``. |
| 67 |
|
| 68 |
Example |
| 69 |
^^^^^^^ |
| 70 |
|
| 71 |
- Request with curl: |
| 72 |
|
| 73 |
:: |
| 74 |
|
| 75 |
curl -X POST -H "Accept: application/json" -d user=rtyler -d password=rtyler http://auth.example.com/ | json_pp |
| 76 |
|
| 77 |
|
| 78 |
.. attention:: |
| 79 |
|
| 80 |
With ``cURL > 7.18.0``, to include special characters |
| 81 |
like @, & or + in the cURL POST data: |
| 82 |
|
| 83 |
:: |
| 84 |
|
| 85 |
curl -X POST -H "Accept: application/json" -d name=rtyler --data-urlencode passwd=@31&3+*J http://auth.example.com/ | json_pp |
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
- Response for bad authentication: |
| 90 |
|
| 91 |
.. code-block:: javascript |
| 92 |
|
| 93 |
{ |
| 94 |
"result" : 0, |
| 95 |
"error" : 5 |
| 96 |
} |
| 97 |
|
| 98 |
- Response for good authentication: |
| 99 |
|
| 100 |
.. code-block:: javascript |
| 101 |
|
| 102 |
{ |
| 103 |
"result" : 1, |
| 104 |
"error" : "0", |
| 105 |
"id" : "b048bf87ca401da1d89419813e3acf466d5e4465fe3a1f7adfd8240bd161bde2" |
| 106 |
} |
| 107 |
|
| 108 |
Sessions |
| 109 |
~~~~~~~~ |
| 110 |
|
| 111 |
REST functions for sessions are protected by Web Server, you can change |
| 112 |
this in :ref:`portal configuration<configlocation-portal>`. |
| 113 |
|
| 114 |
See :doc:`REST session backend documentation<restsessionbackend>` for |
| 115 |
more. |
| 116 |
|
| 117 |
Configuration |
| 118 |
~~~~~~~~~~~~~ |
| 119 |
|
| 120 |
REST functions for configuration are protected by Web Server, you can |
| 121 |
change this in :ref:`portal configuration<configlocation-portal>`. |
| 122 |
|
| 123 |
See :doc:`REST configuration backend documentation<restconfbackend>` for |
| 124 |
more. |