|
| 1 | +from cryptojwt.utils import as_bytes |
| 2 | + |
| 3 | + |
| 4 | +def get_session_status_page(service_context, looked_for_state): |
| 5 | + """ |
| 6 | + Constructs the session status check page |
| 7 | +
|
| 8 | + :param service_context: The relying party's service context |
| 9 | + :param looked_for_state: Expecting state to be ? (changed/unchanged) |
| 10 | + """ |
| 11 | + _msg = open(service_context.add_on['status_check']['template_file']).read() |
| 12 | + _csi = service_context.provider_info['check_session_iframe'] |
| 13 | + _mod_msg = _msg.replace("{check_session_iframe}", _csi) |
| 14 | + if looked_for_state == "changed": |
| 15 | + _mod_msg = _mod_msg.replace( |
| 16 | + "{status_check_iframe}", |
| 17 | + service_context.add_on['status_check']['session_changed_iframe']) |
| 18 | + else: |
| 19 | + _mod_msg = _mod_msg.replace( |
| 20 | + "{status_check_iframe}", |
| 21 | + service_context.add_on['status_check']['session_unchanged_iframe']) |
| 22 | + |
| 23 | + return as_bytes(_mod_msg) |
| 24 | + |
| 25 | + |
| 26 | +def add_status_check_support(service, template_file, rp_iframe_path, |
| 27 | + session_changed_iframe_path, session_unchanged_iframe_path): |
| 28 | + """ |
| 29 | + Setup status check support. |
| 30 | +
|
| 31 | + :param service: Dictionary of services |
| 32 | + :param template_file: Name of template file |
| 33 | + """ |
| 34 | + # Arbitrary which service is used, just want a link to the service context |
| 35 | + authn_service = service["authorization"] |
| 36 | + authn_service.service_context.add_on['status_check'] = { |
| 37 | + "template_file": template_file, |
| 38 | + "rp_iframe_path": rp_iframe_path, |
| 39 | + "session_changed_iframe": session_changed_iframe_path, |
| 40 | + "session_unchanged_iframe": session_unchanged_iframe_path, |
| 41 | + # below are functions |
| 42 | + # "rp_iframe": rp_iframe, |
| 43 | + "get_session_status_page": get_session_status_page |
| 44 | + } |
0 commit comments