Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revision | Next revisionBoth sides next revision | ||
protogrid:json_api_authentication [2022-02-21 23:05] – [JSON API Authentication] dru | protogrid:json_api_authentication [2022-02-21 23:30] – [How to authenticate] dru | ||
---|---|---|---|
Line 7: | Line 7: | ||
Note: Both the email address (e.g. " | Note: Both the email address (e.g. " | ||
- | ==== How to authenticate ==== | + | ==== /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 41: | 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 59: | Line 47: | ||
== Request Axios == | == Request Axios == | ||
- | Example with Axios | ||
<code javascript> | <code javascript> | ||
const axios = require(' | const axios = require(' | ||
Line 65: | 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 77: | Line 64: | ||
}) | }) | ||
.catch((error) => { | .catch((error) => { | ||
- | console.error(' | + | console.error(' |
}); | }); | ||
</ | </ | ||
Line 86: | Line 73: | ||
{ | { | ||
" | " | ||
- | " | + | " |
" | " | ||
} | } | ||
Line 93: | 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”: | ||
} | } |