linotp.lib.reply module¶
create responses
- linotp.lib.reply.apply_detail_policies(response: Response)¶
If policies detail_on_success/detail_on_fail is set, we extend the response with the corresponding details
- linotp.lib.reply.create_html(data, width=0, alt=None, list_id='challenge_data')¶
_create_html - create the qr image data embeded in html tag
- Parameters
data (string) – input data that will be munched into the qrcode
width (int) – image width in pixel
- Returns
<img/> taged data
- Return type
string
- linotp.lib.reply.create_img(data, width=0, alt=None, img_id='challenge_qrcode')¶
_create_img - create the qr image data
- Parameters
data (string) – input data that will be munched into the qrcode
width (int) – image width in pixel
- Returns
<img/> taged data
- Return type
string
- linotp.lib.reply.create_img_src(data)¶
_create_img - create the qr image data
- Parameters
data (string) – input data that will be munched into the qrcode
width (int) – image width in pixel
- Returns
<img/> taged data
- Return type
string
- linotp.lib.reply.create_png(data, alt=None)¶
- linotp.lib.reply.get_details_for_response(response: Response) dict ¶
- Returns details-dict when policy
detail_on_success/detail_on_fail is set
- Args:
login_successful (bool): flag wether login was successful user (User): User to check policy on. E.g. check if logged in admin has access to given User
- Returns:
dict: dict with keys [realm, user, is_linotp_admin, tokentype, serial] or [error]
- linotp.lib.reply.json2xml(json_obj, line_padding='')¶
- linotp.lib.reply.sendCSVIterator(obj, headers=True)¶
- linotp.lib.reply.sendCSVResult(obj, flat_lines=False, filename='linotp-tokendata.csv')¶
returns a CSV document of the input data (like in /admin/show)
- Parameters
obj (JSON object) – The data, that gets serialized as CSV
flat_lines –
- If True the object only contains a list of the
dict { ‘cell’: …, ‘id’: … }
as in all the flexigrid functions.
‘type flat_lines: boolean
- linotp.lib.reply.sendError(exception: Union[Exception, str], id: int = 1)¶
sendError - return a HTML or JSON error result document
Default LinOTP behaviour in case of error is to try to always send a ‘200 OK’ HTTP response that contains an error code and description in the body (JSON data). Some clients prefer a different HTTP status code, because it allows response filtering without parsing the body. If the client sends ‘httperror=<INT>’ in the request this will be honoured (in case of error) and that HTTP status will be set. If ‘httperror’ is set without a value (or an invalid value) status 500 will be used. If you would like this to happen only in some error conditions but not all you can set ‘linotp.errors’ in the LinOTP Config. Then the HTTP status defined by ‘httperror’ will ONLY be sent when the error that occurs in LinOTP matches one of the errors defined in ‘linotp.errors’. In other cases ‘200 OK’ with error code and description in the body will be returned. If ‘linotp.errors’ is unset all errors will cause responses with HTTP status ‘httperror’. For example:
- Setup 1:
The client sends httperror=777 in the request
linotp.errors=233,567
- Case 1.1: An exception is raised in LinOTP that has errId 233.
LinOTP will return a response with HTTP status 777.
- Case 1.2: An exception is raised with errId 555
LinOTP will return a response with HTTP status 200.
- Setup 2:
The client sends httperror (empty) in the request
linotp.errors=233,567
- Case 2.1: An exception is raised in LinOTP that has errId 233.
LinOTP will return a response with HTTP status 500.
- Case 2.2: An exception is raised with errId 555
LinOTP will return a response with HTTP status 200.
- Setup 3:
The client sends httperror (empty) in the request
linotp.errors is not set
- Case 3.1: An exception is raised in LinOTP that has errId 233.
LinOTP will return a response with HTTP status 500.
- Case 3.2: An exception is raised with errId 555
LinOTP will return a response with HTTP status 500.
- Setup 4:
NO httperror in request
linotp.errors=233,567 (or is unset, does not matter)
- Case 4.1: An exception is raised in LinOTP that has errId 233.
LinOTP will return a response with HTTP status 200.
- Case 4.2: An exception is raised with errId 555
LinOTP will return a response with HTTP status 200.
- Parameters
response (response object) – the pylon response object
exception (exception or str) – should be a linotp exception (see linotp.lib.error.py) or a free text error
id (int) – id value, for future versions
- Returns
json rendered string result
- Return type
string
- linotp.lib.reply.sendQRImageResult(data, param=None, id=1, typ='html')¶
- method
sendQRImageResult
- arguments
param - the paramters of the request id - html - print qrcode wrapped by html or not
- linotp.lib.reply.sendResult(obj, id=1, opt=None, status=True)¶
sendResult - return an json result document
- Parameters
obj (dict or list or string/unicode) – simple result object like dict, string or list
id (int) – id value, for future versions
opt (None or simple type like dict, list or string/unicode) – optional parameter, which allows to provide more detail
- Returns
json rendered string result
- Return type
string
- linotp.lib.reply.sendResultIterator(obj, id=1, opt=None, rp=None, page=None, request_context_copy=None)¶
- sendResultIterator - return an json result document in a streamed mode
which requires a request context to be avaliable
- Parameters
obj – iterator of generator object like dict, string or list
id – id value, for future versions
opt – optional parameter, which allows to provide more detail
rp – results per page
page – number of page
- Returns
generator of response data (yield)
- linotp.lib.reply.sendXMLError(exception, id=1)¶
- linotp.lib.reply.sendXMLResult(obj, id=1, opt=None)¶
send the result as an xml format
- linotp.lib.reply.validate_transactions(response: Response) bool ¶
Returns False if there are transactions and none of them is validated. Otherwise returns True.
- linotp.lib.reply.was_login_successful(response: Response) bool ¶