Authorization header
To authenticate using Basic authentication, the Authorization
header must
specify the Basic
scheme followed by the base64 encoding of the requester's
username and API token delimited by a colon. The API token is returned by the
/api/v2/sessions endpoint as apiToken
. For convenience,
the /api/v2/sessions endpoint also returns a
basicAuthenticationCredentials
field containing the encoded username and
token, which can be injected directly into the Authorization header.
Example header:
Authorization: Basic {basicAuthenticationCredentials}
Creating a session via the /api/v2/sessions endpoint
Create an API session by sending a POST
request to the
/api/v2/sessions endpoint with a request body containing the user's
credentials.
Request
POST http://{Address_Manager_IP}/api/v2/sessions
Content-Type: application/json
{
"username": "user1",
"password": "pass1"
}
Sample curl call
curl -v -d '{"username":"user1", "password":"pass1"}' -X POST -H "Content-Type: application/json" http://{Address_Manager_IP}/api/v2/sessions
The response will contain an apiToken
value that can be combined with the
username and encoded for the Authorization
header of RESTful v2 API requests.
The response will also contain a basicAuthenticationCredentials
field that
can be injected directly.
Response
HTTP/1.1 201 Created
Content-Type: application/hal+json
{
"id": 62,
"type": "UserSession",
"apiToken": "/LOcpzfqKXgvt3PH0xYNhFqTewfnF5SNz7Fh/ST8",
"apiTokenExpirationDateTime": "2023-01-21T21:40:48Z",
"basicAuthenticationCredentials": "YXBpOi9MT2NwemZxS1hndnQzUEgweFlOaEZxVGV3Zm5GNVNOejdGaC9TVDg=",
"state": "LOGGED_IN",
"remoteAddress": "192.168.217.248",
"readOnly": false,
"loginDateTime": "2023-01-20T21:40:48Z",
"logoutDateTime": null,
"response": null,
"user": {
"id": 100893,
"type": "User",
"name": "user1",
"_links": {
"self": {
"href": "/api/v2/users/100893"
}
}
},
"authenticator": {
"id": 2,
"type": "AddressManagerAuthenticator",
"name": "proteusAuthenticator",
"_links": {
"self": {
"href": "/api/v2/authenticators/2"
}
}
},
"_links": {
"self": {
"href": "/api/v2/sessions/62"
},
"collection": {
"href": "/api/v2/sessions"
}
}
}