-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy patht-03-auth-03-xades.py
More file actions
executable file
·33 lines (31 loc) · 1.03 KB
/
t-03-auth-03-xades.py
File metadata and controls
executable file
·33 lines (31 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/usr/bin/env vpython3
import json
import requests
import sys
from ksefconfig import Config
def main():
cfg = Config(int(sys.argv[1]), sys.argv[2]=='o')
with open(f'{cfg.prefix}-auth.xml.xades', 'rb') as fp:
xml = fp.read()
resp = requests.post(
cfg.url+'/auth/xades-signature?verifyCertificateChain=false',
data=xml,
headers={
"Content-Type": "application/xml",
"X-KSeF-Feature": "enforce-xades-compliance",
},
timeout=5
)
print('post_api_v2_auth_xades_signature:', resp)
if resp.status_code == 202:
data = resp.json()
with open(f'{cfg.prefix}-auth.temp.json', 'wt') as fp:
fp.write(json.dumps(data))
print('authenticationToken', data['authenticationToken'])
print('a.token', data['authenticationToken']['token'])
print('a.valid', data['authenticationToken']['validUntil'])
print('referenceNumber', data['referenceNumber'])
else:
print(resp.text)
print(resp.headers)
main()