Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
protogrid:json_api_authentication [2019-12-18 15:51] – jus | protogrid:json_api_authentication [2022-02-21 23:30] – [How to authenticate] dru | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== JSON API Authentication ====== | ====== JSON API Authentication ====== | ||
- | At the moment only Basic Authentication is supported. If you need OAuth2 please contact us at [[mailto: | + | All HTTP requests |
+ | * [[https:// | ||
+ | * Header | ||
+ | * Cookie Authentication using the session cookie returned after a successfull authentication with one of the upper two variants. | ||
- | ==== How to authenticate ==== | + | Note: Both the email address (e.g. " |
+ | ==== /api/v2/authenticate ==== | ||
+ | |||
+ | [POST] In order to obtain a session cookie you can use the authentication endpoint. | ||
- | A POST http request to the API endpoint “/ | ||
- | HTTP header fields: | ||
- | | < | ||
- | | ::: |Either < | ||
- | | < | ||
- | | ::: |Either < | ||
- | |< | ||
=== Examples === | === Examples === | ||
- | == Request | + | |
- | Example request: | + | == HTTP == |
< | < | ||
- | https:// | + | POST /api/v2/ |
+ | Host: example.protogrid.com | ||
+ | username: example_user | ||
+ | password: test_password | ||
</ | </ | ||
- | Request header: | ||
- | <code json> | ||
- | { | ||
- | POST / | ||
- | Host: your_environment.protogrid.com | ||
- | user_id: example_user | ||
- | user_secret: | ||
- | } | ||
- | </ | ||
- | == Request jQuery == | ||
- | Example in jQuery: | ||
- | < | + | == jQuery == |
+ | < | ||
$.ajax({ | $.ajax({ | ||
type:' | type:' | ||
Line 37: | Line 29: | ||
dataType: ' | dataType: ' | ||
beforeSend: function(xhr){ | beforeSend: function(xhr){ | ||
- | xhr.setRequestHeader(' | + | xhr.setRequestHeader(' |
- | xhr.setRequestHeader(' | + | xhr.setRequestHeader(' |
} | } | ||
}); | }); | ||
</ | </ | ||
- | == Request | + | == Python == |
- | Example in Python (with requests): | + | |
<code python> | <code python> | ||
+ | import requests | ||
url = " | url = " | ||
- | headers = dict(user_id="test_user@testdomain.com", user_secret=" | + | headers = dict(username="testuser@example.com", user_secret=" |
req = requests.post(url, | req = requests.post(url, | ||
response = req.text | response = req.text | ||
Line 55: | Line 47: | ||
== Request Axios == | == Request Axios == | ||
- | Example with Axios | ||
<code javascript> | <code javascript> | ||
const axios = require(' | const axios = require(' | ||
Line 61: | Line 52: | ||
headers: { | headers: { | ||
' | ' | ||
- | 'user_email': 'test_user@testdomain.com', | + | 'username': 'testuser@example.com', |
- | 'user_secret': ' | + | 'password': ' |
} | } | ||
}) | }) | ||
.then((result) => { | .then((result) => { | ||
- | console.log(' | + | console.log(' |
var cookies_from_resp = res.headers[' | var cookies_from_resp = res.headers[' | ||
var cookie_for_session = cookies_from_resp[0].split(';' | var cookie_for_session = cookies_from_resp[0].split(';' | ||
Line 73: | Line 64: | ||
}) | }) | ||
.catch((error) => { | .catch((error) => { | ||
- | console.error(' | + | console.error(' |
}); | }); | ||
</ | </ | ||
Line 82: | Line 73: | ||
{ | { | ||
" | " | ||
- | " | + | " |
" | " | ||
} | } | ||
Line 89: | Line 80: | ||
== Unsuccessful Response == | == Unsuccessful Response == | ||
Example response of unsuccessful authentication: | Example response of unsuccessful authentication: | ||
- | < | + | < |
{ | { | ||
“errors”: | “errors”: | ||
{ | { | ||
- | “code”: | + | “code”: |
- | “message”: | + | “message”: |
- | address and password.” | + | |
} | } | ||
], | ], | ||
- | " | + | " |
“result”: | “result”: | ||
} | } |