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:29] – cso | protogrid:json_api_authentication [2019-12-18 15:51] – jus | ||
---|---|---|---|
Line 21: | Line 21: | ||
<code json> | <code json> | ||
{ | { | ||
- | POST / | + | |
- | Host: your_environment.protogrid.com | + | Host: your_environment.protogrid.com |
- | user_id: example_user | + | user_id: example_user |
- | user_secret: | + | user_secret: |
} | } | ||
</ | </ | ||
Line 32: | Line 32: | ||
<code jquery> | <code jquery> | ||
$.ajax({ | $.ajax({ | ||
- | | + | |
- | url: ' | + | url: ' |
- | contentType: | + | contentType: |
- | dataType: ' | + | dataType: ' |
- | beforeSend: function(xhr){ | + | beforeSend: function(xhr){ |
- | xhr.setRequestHeader(' | + | xhr.setRequestHeader(' |
- | xhr.setRequestHeader(' | + | xhr.setRequestHeader(' |
- | } | + | } |
}); | }); | ||
</ | </ | ||
Line 52: | Line 52: | ||
response = json.loads(response) | response = json.loads(response) | ||
cookie = req.cookies[' | cookie = req.cookies[' | ||
+ | </ | ||
+ | |||
+ | == Request Axios == | ||
+ | Example with 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 58: | Line 81: | ||
<code json> | <code json> | ||
{ | { | ||
- | " | + | |
- | " | + | " |
- | " | + | " |
} | } | ||
</ | </ | ||
Line 66: | Line 89: | ||
== Unsuccessful Response == | == Unsuccessful Response == | ||
Example response of unsuccessful authentication: | Example response of unsuccessful authentication: | ||
- | < | + | < |
{ | { | ||
- | “errors”: | + | |
- | { | + | { |
- | “code”: 401, | + | “code”: 401, |
- | “message”: | + | “message”: |
- | address and password.” | + | address and password.” |
- | } | + | } |
- | ], | + | ], |
- | " | + | " |
- | “result”: | + | “result”: |
} | } | ||
</ | </ | ||
Line 89: | Line 112: | ||
<code jquery> | <code jquery> | ||
$jq.ajax({ | $jq.ajax({ | ||
- | | + | |
- | url: ' | + | url: ' |
- | contentType: | + | contentType: |
- | dataType: ' | + | dataType: ' |
- | success: function(data) { | + | success: function(data) { |
- | console.log(data); | + | console.log(data); |
- | }, | + | }, |
- | error: function(data) { console.log(data); | + | error: function(data) { console.log(data); |
}); | }); | ||
</ | </ | ||
Line 104: | Line 127: | ||
Example Python request: | Example Python request: | ||
<code python> | <code python> | ||
- | The cookie variable was set above in the authenticate example. | + | # The cookie variable was set above in the authenticate example. |
url = " | url = " | ||
req = requests.get(url, | req = requests.get(url, | ||
Line 111: | Line 134: | ||
</ | </ | ||
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(' | ||
+ | }); | ||
+ | </ | ||