This method checks the login data of the user and on successful verification opens a new Web API session. The method requests the name and the password of the user in plain text as proof of authorization. The user name and the password are encrypted before they are transferred to the server.
No authorization is required to call the Api.Login method.
Structure of the request
The following table provides information about the required parameters for the request.
Name |
Required |
Data type |
Description |
|---|---|---|---|
mode |
No |
string |
Login mode. You can use all the modes supported by the Api.GetAuthenticationMode method, see Api.GetAuthenticationMode. If no parameter is used, the query is assumed to be "local". |
user |
Yes |
string |
The user name. The parameter must be specified in the following modes: "static", "disabled", "local" and "umc". |
password |
Yes |
string |
The current password in plain text, without encryption. The parameter must be specified in the following modes: "static", "disabled", "local" and "umc". |
include_web_application_cookie |
No |
bool |
This parameter specifies:
|
Example 1
The following example shows the parameters required to call an Anonymous user.
{
"user": "Anonymous",
"password": ""
}
Example 2
The following example shows the parameters required to call a regular user.
{
"user": "user_1",
"password": "1234"
}
Example 3
The following example shows the parameters required to call an Anonymous user with local user management.
{
"mode": "local",
"user": "user_1",
"password": "1234"
}
Example 4
The following example shows the parameters required to call an Anonymous user with central user management.
{
"mode": "umc",
"user": "user_1",
"password": "1234"
}
Token
The token comprises a 28-byte string. The token is transferred in encrypted form.
For every additional request which requires authentication, you have to specify the assigned token in the HTTP request header. If further communication no longer takes place in the meantime, the token becomes invalid after maximum 2.5 minutes. Each new request within a session extends the validity of the token by another 2 to 2.5 minutes, calculated from the completion of the request processing by the server.
The token is not required for methods that do not require authentication. However, you can still enter the token. If the token is passed when a method is called, the timeout of the corresponding session is reset.
When you call, for example, the Api.Ping method without a token, the session is not extended because the CPU cannot assign a token to the user.
The following methods, amongst others, work with and without tokens:
Api.Browse
Api.Ping
Api.GetPermissions
Receiving a token for a passwordless user account without password
If a user wants to use a user account without password to access the Web API, they must authenticate with the API method Api.Login using the user name "Everybody"/"Anonymous" and an empty password ("").
Even if only the central user management was activated, an Anonymous user can be present on the CPU, in as far as it was activated. In this case the GetAuthenticationMode method only returns "umc", but not "local". Nevertheless, a login with mode=local or without mode parameter is possible.
The name of the specific user depends on the firmware version of the CPU:
For projects with a firmware version ≤ V3.0: Static user management with the user "Everybody"
For projects with a firmware version ≥ V3.1: Local user management with "Anonymous" user
For projects with a firmware version ≥ V4.0: Local or central user management with "Anonymous" user
The "Anonymous" user can be deactivated in STEP 7 and is then not available on the CPU. Non-activated users are not downloaded to the CPU. This means that a call of the API method Api.Login with the user name "Anonymous" fails if the user was deactivated in STEP 7.
User "Everybody"/"Anonymous"
Note that, unlike TIA Portal, the Web API only accepts the English notation "Everybody" or "Anonymous".
The session token is security-relevant. You are not permitted to forward it or pass it on.
Response structure
The following tables show the structure of server responses to successful requests.
Name |
Required |
Data type |
Description |
|---|---|---|---|
token |
Yes |
string |
The token indicates that its holder has successfully authenticated themselves at the Web API. The returned token must be passed via the HTTP request header "X-Auth-Token" in subsequent Web API requirements. |
web_application_cookie |
No |
string |
Only present if "include_web_application_cookie" is "true". The holder of the token has successfully authenticated themselves with the Web API and has authorization to access protected web applications. |
password_expiration |
No |
object of type Api_Login_PasswordExpiration_Response |
This object contains information on the expiration of the password, if:
|
runtime_timeout |
No |
string |
ISO 8601 time span as string Time span of inactivity in seconds after which a client application is to perform a logout using the API method Api.Logout. |
has_no_permissions |
No |
bool |
If the user does not have authorization to access the web server, true is returned. |
Name |
Required |
Data type |
Description |
|---|---|---|---|
timestamp |
Yes |
string |
ISO8601 time stamp as a string in Coordinated Universal Time (UTC) Indicates when the user password expires. The accuracy must be specified in seconds. |
warning |
Yes |
bool |
This parameter specifies whether the warning threshold was reached before the password expired. |
Example 1
The example below shows a successful login for a user without expiration of the password (either static user management or password expiration deactivated):
{
"token": "TXlMdWdnYWdlSGFzVGhlU2FtZSE="
}
Example 2
The following example shows a successful login for a user with password expiration:
{
"token": "TXlMdWdnYWdlSGFzVGhlU2FtZSE=",
"password_expiration":
{
"timestamp": "2023-11-05T18:25:43Z",
"warning": true
}
}
Example 3
The following example shows a successful login for a user with password expiration and runtime_timeout of 30 minutes:
{
"token": "TXlMdWdnYWdlSGFzVGhlU2FtZSE=",
"runtime_timeout": "PT30M",
"password_expiration":
{
"timestamp": "2023-11-05T18:25:43Z",
"warning": true
}
}
Possible error messages
The following table shows possible error messages of the Api.Login method.
Error code |
Error message |
Meaning |
|---|---|---|
4 |
No resources |
The system does not have the required resources to carry out this request. Perform the request once more as soon as enough resources are available again. |
6 |
Not accepted |
The authentication cannot be performed because the mode is not supported by the CPU. |
100 |
Login failed |
The user name and/or password are not permissible. Assign a permissible user name and a permissible password. Another reason why the login failed may be an active brute force attack. |
101 |
Already authenticated |
The current authentication token is already authenticated. Use Api.Logout before you authenticate yourself again. |
102 |
Login Failed - Password expired |
The password of the user account has expired. The user must change the password in order to be able to successfully authenticate again. |
105 |
Login Failed - Infrastructure Error |
The authentication was not successful, for example because the server cannot be reached. |