Webservice Authentication

Login

Before any web service action can be done, the client application must first authenticate with KnowledgeTree. This is done by invoking the login method that will start a new session.

login(username, password, ip, app) : kt_response
Field Type Description
usernameStringThe username of the user that needs to access the repository.
passwordStringThe associated password of the user.
ipStringThe IP address of the user. This is logged for authentication purposes only.
appStringName of the application. This is used to distinguish between unique logins from different applications. By default all applications are identified as “ws” or webservice.
Response

A kt_response object is returned.

The response should have status_code = 0 and the message field contains a session reference that will be used in subsequent requests.

Sample psuedo code
response = webservice.login('admin','admin', '127.0.0.1')
if response.status_code != 0 
    raise 'Cannot authenticate. Reason: ' + response.message 
end
session = response.message
Implementation Notes

It is not necessary to create a new session before each action. The application should create a session once, store it and reuse the session reference. Sessions do have a lifetime that is configured by the server. If a session expires, a new session will need to be created.

Logout - End a Session

The client application can terminate a session by calling the logout method.

logout(session) : kt_response
Field Type Description
sessionStringThe session returned during the authentication process.
Response

A kt_response object is returned.

Sample psuedo code
response = webservice.logout('3a598320171890920a6b13f7fcc69dce')
if response.status_code != 0 
    log 'Problem logging out. Reason: ' + response.message 
end

Anonymous Login

If anonymous access is required, the anonymous_login may be used:

anonymous_login(ip) : kt_response
Field Type Description
ipStringThe ip address of the user.
Response

A kt_response object is returned.

Sample psuedo code
response = webservice.anonymous_login('127.0.0.1')
if response.status_code != 0 
    log 'Problem logging out. Reason: ' + response.message 
end

Session Token

The login method returns a session token. The token must be used in all functions that require the user to be logged in. It is used to maintain a session on the server within the stateless nature of the API. Depending on how the system has been configured, it will expire after 24 hours of disuse.