Sessions¶
httpkom.sessions
¶
The httpkom connection id is the unique identifier that a httpkom client uses to identify which LysKOM connection that it owns. Since httpkom can be configured to allow connections to several different LysKOM servers, the connection id refers to a specific session on a specific LysKOM server.
The session number is what the LysKOM server uses to identify an open connection.
There is a 1-to-1 relation between httpkom connection ids and LysKOM session numbers. The important difference between the session number and the connection id, is that the session number is not secret. Httpkom uses a separate connection identifier, the httpkom connection id (a random UUID), to make it close to impossible to intentionally take over another httpkom client's LysKOM connection.
The httpkom connection id is specified as a HTTP header:
To open a new connection, make a request like this:
POST /<server_id>/sessions/
Content-Type: application/json
{ "client": { "name": "jskom", "version": "0.6" } }
The response will look like this:
HTTP/1.0 201 Created
Content-Type: application/json
Httpkom-Connection: <uuid>
{ "session_no": 123456 }
This is the only response that will contain the Httpkom-Connection. The request must not contain any Httpkom-Connnection header. If the request contains a Httpkom-Connection header, the request will fail and the response will be:
Subsequent request to that server should contain the returned Httpkom-Connection header. For example, a login request will look like this:
POST /<server_id>/sessions/current/login
Content-Type: application/json
Httpkom-Connection: <uuid>
{ "pers_no": 14506, "passwd": "test123" }
and the response:
HTTP/1.0 201 Created
Content-Type: application/json
{ "pers_no": 14506, "pers_name": "Oskars Testperson" }
If a resource requires a logged in session and the request contains a valid Httpkom-Connection header which is not logged in, the response will be:
If the Httpkom-Connection is missing, or if the connection id specified
by the Httpkom-Connection header is invalid (for example if the
connection was to another server than
When you get a 403 response, the used Httpkom-Connection should be
considered invalid and should not be used again. If the
Httpkom-Connection specifies a working connection, but to another
server than
It is up to the client to keep track of opened connection and to use
them with the correct
sessions_who_am_i()
async
¶
sessions_current_active()
async
¶
Tell the LysKOM server that the current user is active.
Request:
Response:
Example:
sessions_create()
async
¶
Create a new session (a connection to the LysKOM server).
Note: The response body also contains the connection_id (in addition to the response header) to around problems with buggy CORS implementations (bug 608735) in combination with certain javascript libraries (AngularJS).
Request:
Responses:
Successful connect:
HTTP/1.0 201 Created
Httpkom-Connection: 033556ee-3e52-423f-9c9a-d85aed7688a1
{
"session_no": 12345,
"connection_id": "033556ee-3e52-423f-9c9a-d85aed7688a1"
}
If the request contains a Httpkom-Connection header:
sessions_login()
async
¶
Log in using the current session.
Note: If the login is successful, the matched full name will be returned in the response.
Request:
POST /<server_id>/sessions/current/login HTTP/1.1
Httpkom-Connection: <id>
{
"pers_no": 14506,
"passwd": "test123"
}
Or
POST /<server_id>/sessions/current/login HTTP/1.1
Httpkom-Connection: <id>
{
"pers_name": "Oskars",
"passwd": "test123"
}
Responses:
Successful login:
Failed login:
Example:
sessions_logout()
async
¶
Log out in the current session.
Request:
Responses:
Successful logout:
Example:
sessions_delete(session_no)
async
¶
Delete a session (disconnect from the LysKOM server).
If the request disconnects the current session, the used Httpkom-Connection id is no longer valid.
Note (from the protocol A spec): "Session number zero is always interpreted as the session making the call, so the easiest way to disconnect the current session is to disconnect session zero."
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_no
|
int
|
Session number. |
required |
Request:
Responses:
Success:
Session does not exist:
Example: