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 [2017-12-08 17:37] – pgrid_wiki_admin | 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 | ||
response = json.loads(response) | response = json.loads(response) | ||
cookie = req.cookies[' | cookie = req.cookies[' | ||
+ | </ | ||
+ | |||
+ | == Request Axios == | ||
+ | <code javascript> | ||
+ | const axios = require(' | ||
+ | axios.post(' | ||
+ | headers: { | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | } | ||
+ | }) | ||
+ | .then((result) => { | ||
+ | console.log(' | ||
+ | var cookies_from_resp = res.headers[' | ||
+ | var cookie_for_session = cookies_from_resp[0].split(';' | ||
+ | | ||
+ | // send authenticated http request here (see documentation below) | ||
+ | }) | ||
+ | .catch((error) => { | ||
+ | console.error(' | ||
+ | }); | ||
</ | </ | ||
Line 59: | Line 73: | ||
{ | { | ||
" | " | ||
- | " | + | " |
" | " | ||
} | } | ||
Line 66: | 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”: | ||
} | } | ||
Line 111: | Line 124: | ||
</ | </ | ||
Note: For more information about the requests, please refer to http:// | Note: For more information about the requests, please refer to http:// | ||
+ | |||
+ | == Example Axios == | ||
+ | Example request with Axios: | ||
+ | <code javascript> | ||
+ | axios.get(' | ||
+ | headers: { | ||
+ | ' | ||
+ | ' | ||
+ | } | ||
+ | }) | ||
+ | .then((result) => { | ||
+ | console.log(' | ||
+ | console.log(result.data); | ||
+ | }) | ||
+ | .catch((error) => { | ||
+ | console.log(' | ||
+ | }); | ||
+ | </ | ||