|
2 | 2 | from datetime import datetime |
3 | 3 | from datetime import timedelta |
4 | 4 | from imio.esign import _tr as _ |
5 | | -from imio.esign import ESIGN_CREDENTIALS |
6 | 5 | from imio.esign import ESIGN_ROOT_URL |
7 | 6 | from imio.esign.interfaces import IContextUidProvider |
8 | 7 | from imio.helpers.content import uuidsToObjects |
9 | 8 | from imio.helpers.content import uuidToObject |
10 | 9 | from imio.helpers.transmogrifier import get_correct_id |
11 | | -from imio.pyutils.system import post_request |
| 10 | +from imio.helpers.ws import get_auth_token |
12 | 11 | from imio.pyutils.utils import shortuid_encode_id |
13 | 12 | from os import path |
14 | 13 | from persistent.list import PersistentList |
|
19 | 18 |
|
20 | 19 | import json |
21 | 20 | import logging |
| 21 | +import requests |
22 | 22 |
|
23 | 23 |
|
24 | 24 | logger = logging.getLogger("imio.esign") |
@@ -86,11 +86,10 @@ def add_files_to_session( |
86 | 86 | return session_id, session |
87 | 87 |
|
88 | 88 |
|
89 | | -def create_external_session(session_id, b64_cred=None, esign_root_url=None): |
| 89 | +def create_external_session(session_id, esign_root_url=None): |
90 | 90 | """Create a session with the given signers and files. |
91 | 91 |
|
92 | 92 | :param session_id: internal session id |
93 | | - :param b64_cred: base64 encoded credentials for authentication |
94 | 93 | :param esign_root_url: the root URL for the e-sign service, if not provided it will use the default ESIGN_ROOT_URL |
95 | 94 | :return: session information |
96 | 95 | """ |
@@ -145,17 +144,21 @@ def create_external_session(session_id, b64_cred=None, esign_root_url=None): |
145 | 144 | "sealCode": seal_code, |
146 | 145 | } |
147 | 146 |
|
| 147 | + # files_payload = {filename: file_content for z, filename, file_content, uid in files} |
148 | 148 | files_payload = [("files", (filename, file_content)) for z, filename, file_content, uid in files] |
149 | 149 |
|
150 | 150 | # Headers avec autorisation |
151 | | - headers = {"accept": "application/json"} |
152 | | - b64_cred = b64_cred or ESIGN_CREDENTIALS |
153 | | - if b64_cred: |
154 | | - headers["Authorization"] = "Basic {}".format(b64_cred) |
| 151 | + headers = { |
| 152 | + "accept": "application/json", |
| 153 | + "Authorization": "Bearer %s" % get_auth_token(), |
| 154 | + } |
155 | 155 |
|
156 | 156 | logger.info(data_payload) |
157 | | - ret = post_request( |
158 | | - session_url, data={"data": json.dumps(data_payload, default=vars)}, headers=headers, files=files_payload |
| 157 | + ret = requests.post( |
| 158 | + session_url, |
| 159 | + headers=headers, |
| 160 | + data={"data": json.dumps(data_payload, default=vars)}, |
| 161 | + files=files_payload, |
159 | 162 | ) |
160 | 163 | if ret.status_code == 200: |
161 | 164 | session["state"] = "sent" |
|
0 commit comments