Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Next revisionBoth sides next revision
protogrid:json_api_authentication [2022-02-22 00:12] druprotogrid:json_api_authentication [2022-02-22 23:09] – [/api/v2/authenticate] dru
Line 1: Line 1:
 ====== JSON API Authentication ====== ====== JSON API Authentication ======
-All HTTP requests to the Protogrid JSON API require a valid authentication. If the authentication fails an HTTP error 403 will be returned. The following variants are available for authentication:+All HTTP requests to the Protogrid JSON API require a valid authentication. If the authentication fails an HTTP error 403 will be returned. 
 + 
 +The following variants are available for authentication in all JSON API endpoints:
   * Header authentication using the HTTP headers 'username' and 'password'.   * Header authentication using the HTTP headers 'username' and 'password'.
   * [[https://en.wikipedia.org/wiki/Basic_access_authentication|HTTP basic authentication (BA)]]   * [[https://en.wikipedia.org/wiki/Basic_access_authentication|HTTP basic authentication (BA)]]
-  * Cookie authentication using the session cookie returned after a successfull authentication with one of the upper two variants.+  * Cookie authentication (a valid session cookie is part of the response of each successful authenticated JSON API request).
  
 Note: Both the email address (e.g. "testuser@example.com") and the user ID (e.g. "1957f847-f298-4f14-a031-7ffbe31aeb47") can be used for "username". Note: Both the email address (e.g. "testuser@example.com") and the user ID (e.g. "1957f847-f298-4f14-a031-7ffbe31aeb47") can be used for "username".
  
-==== /api/v2/authenticate ====+===== /api/v2/authenticate =====
 [POST] In order to obtain a session cookie you can use the authentication endpoint. [POST] In order to obtain a session cookie you can use the authentication endpoint.
  
-For this endpoint, in addition to the three variants above, the credentials can also be passed as JSON in the request body:+Note: For this endpoint, in addition to the three variants above, the credentials can also be passed as "application/json" in the request body:
 <code javascript> <code javascript>
 { {
Line 18: Line 20:
 </code> </code>
  
-==== Examples to obtain a session cookie using the authentication endpoint with header authentication ====+===== Examples obtaining a session cookie using the authentication endpoint with header authentication =====
  
-=== HTTP ===+==== HTTP ====
 <code> <code>
 POST /api/v2/authenticate POST /api/v2/authenticate
Line 28: Line 30:
 </code> </code>
  
-=== jQuery ===+==== jQuery ====
 <code javascript> <code javascript>
 $.ajax({ $.ajax({
Line 42: Line 44:
 </code> </code>
  
-=== Python ===+==== Python ====
 <code python> <code python>
 import requests import requests
Line 53: Line 55:
 </code> </code>
  
-=== Axios ===+==== Axios ====
 <code javascript> <code javascript>
 const axios = require('axios'); const axios = require('axios');
Line 75: Line 77:
 </code> </code>
  
-=== Success Response ===+==== Success Response ====
 Example response of successful authentication: Example response of successful authentication:
 <code javascript> <code javascript>
Line 85: Line 87:
 </code> </code>
  
-=== Error Response ===+==== Error Response ====
 Example response of unsuccessful authentication: Example response of unsuccessful authentication:
 <code javascript> <code javascript>
Line 100: Line 102:
 </code> </code>
  
-==== Example HTTP requests using a previously obtained session cookie ====+===== Examples using a previously obtained session cookie =====
  
-=== HTTP ===+==== HTTP ====
 <code> <code>
 GET /api/v2/apps GET /api/v2/apps
Line 109: Line 111:
 </code> </code>
  
-=== jQuery ===+==== jQuery ====
 <code javascript> <code javascript>
 $.ajax({ $.ajax({
Line 128: Line 130:
 In particular, this means that you usually don't need to worry about authentication if you use JSON API requests in [[protogrid:script_library|Client Script Libraries]]. In particular, this means that you usually don't need to worry about authentication if you use JSON API requests in [[protogrid:script_library|Client Script Libraries]].
  
-=== Python ===+==== Python ====
 <code python> <code python>
 # The cookie variable was set above in the authentication example. # The cookie variable was set above in the authentication example.
Line 138: Line 140:
 For more information about the requests library, please refer to [[http://docs.python-requests.org/en/master/|the official documentation]]. For more information about the requests library, please refer to [[http://docs.python-requests.org/en/master/|the official documentation]].
  
-=== Axios ===+==== Axios ====
 <code javascript> <code javascript>
 axios.get('https://example.protogrid.com/api/v2/apps', { axios.get('https://example.protogrid.com/api/v2/apps', {
Print/export