API Authentication
API Authentication
If there is a controller password or Web Interface Access Users setup in the project, then Authorisation will be required to use the HTTP or JavaScript API.
There are two types of Authorisation available, which can be used in different situations:
1. Cookie Authentication
2. Token Authentication
Note:
Both these authentication methods will expire after 5 mins of inactivity
Cookie Authentication
Cookie Authentication is typically used by the web interface (either Default or Custom), and stores a small file on your computer, which lets the controller know that you are currently signed in.
This authentication is provided through the Default Login page, when using the Default Web Interface, or a Custom
Web Interface, without a Custom login page defined.
Custom Login Page
If a Custom Web Interface is being used, then a Custom Login page can be configured. Typically this will be a HTML based page with a form element containing a username and password entry field. The code below can be used to generate these fields, and send the data to the controller's web server to authenticate the user and store the Cookie:
<form action="/authorise" method="POST">
<input type="text" name="user">
<input type="password" name="password">
<button type="submit">Submit</button>
</form>
Token Authentication
Token Authentication is typically used by the HTTP API, where there isn't necessarily a method to enter the username and password manually.
Token Authentication works by the user requesting a Bearer Token from the controller, with the username and password, and this token is then used in future requests.
To request a Bearer Token:
1. Send a HTTP request to http://[ip address]/token in the following format:
Method: POST
Headers:
- 411 -
Pharos Designer User Manual
Content-Type: application/json
Body:
{"user":[username], "password":[password]}
2. If successful you will receive a response containing the following JSON Object:
{
"access_token": "[some_access_token]",
"expires_in": 300,
"token_type": "Bearer"
}
3. Subsequent requests will require the following header
Authorization: Bearer [some_access_token]
- 412 -