Timeout for Web API sessions
If a Web API call is not made within a session before 120 seconds have elapsed, the CPU terminates the session with a logout event. A timeout reset is initiated by every successful action of the user in which a toke is supplied.
Call the Api.GetPermission or Api.Ping method cyclically within the timeout grid to ensure that:
Your session remains active
Your authorizations for the call of other methods remain active
Limitations for Web API sessions
The CPU limits the number of active sessions. The following table shows the limitations, meaning the available resources depending on the CPU used.
CPUs |
Limitation |
|---|---|
1510 to 1513 |
50 |
1514, 1515, 1516 and 1504D TF |
100 |
1517, 1518, 1516T and 1507D TF |
200 |
Limitation of the active Web API sessions
If you request another authentication token and none are available, the request is rejected.
Each call of Api.Login means a new authentication token. This applies for every user, also for activated "Anonymous" user.
Change as of firmware version V4.0: In contrast to users with password, only one resource is still occupied for the "Anonymous" user in the CPU, instead of <n> resources, if "Anonymous" authenticates themselves <n> times in parallel. This means that Anonymous users no longer occupy the maximum session resources of the CPU.
The authorization on the web server as an "Anonymous" user is only foreseen for test purposes, commissioning, etc. In other words, when the system is not in productive operation. In this case, you have to ensure the security of the plant through other organizational measures, e.g. spatial protection. This user is described in more details in the section User management.
Changes to CPU user administration
The following applies to configured CPUs with firmware version ≤ V3.0: If the configuration of the CPU user management changes (by downloading the HW configuration in the TIA Portal), e.g. password changed or user removed, the CPU terminates all sessions with a logout event.
The following applies to configured CPUs with firmware version ≥ V3.1: If a user has been authenticated and the project is subsequently loaded into the CPU, deleted or deactivated users are logged out. If only the password or role of the user changes, the user remains authenticated.
Security events
The following applies to configured CPUs with firmware version ≤ V3.0: The CPU generates a security event for successful and failed logins. The CPU enters this security event in the diagnostics buffer.
For configured CPUs with firmware version ≥ V3.1, security events are logged in the CPU's internal syslog buffer.
For more information on Syslog messages, refer to the S7-1500, ET 200MP System Manual.
Authentication token
You must be able to limit the access to the functions of the CPU in order to ensure both the security as well as the protection of your process. This functionality was realized in the previous web server by specifying user accounts and authorizations. No authorization or several authorizations can be assigned to each user. When the user executes functions on the CPU, the CPU checks whether the user disposes of the corresponding authorizations before the requested action is carried out.
The authentication token is the result of a successful login using the Api.Login method.
This token must be transferred to the Web API at all the subsequent API requests after a successful login as an HTTP header "X-Auth-Token".
In the following example, the X-Auth-Token is passed on as an HTTP header to the request:
$.post({
url:"https://192.168.2.132/api/jsonrpc",
data:JSON.stringify({jsonrpc:"2.0",id:1,
method:"RequestChangeOperatingMode",params:{mode:"run"}}),
success: function(data){ console.log(data); },
dataType: "text",
contentType: "application/json",
headers: {
"X-Auth-Token":"VGhpc0lzU2hvcnRUb1ByZXZlbnRXcmFwcGluZw=="}});
You can find a description of the method in the section Api.Login.