-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathptxAuth.py
More file actions
executable file
·26 lines (23 loc) · 943 Bytes
/
Copy pathptxAuth.py
File metadata and controls
executable file
·26 lines (23 loc) · 943 Bytes
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
from hashlib import sha1
import hmac
from wsgiref.handlers import format_date_time
from datetime import datetime
from time import mktime
import base64
class Auth():
def __init__(self, app_id, app_key):
self.app_id = app_id
self.app_key = app_key
def get_auth_header(self):
xdate = format_date_time(mktime(datetime.now().timetuple()))
hashed = hmac.new(self.app_key.encode('utf8'), ('x-date: ' + xdate).encode('utf8'), sha1)
signature = base64.b64encode(hashed.digest()).decode()
authorization = 'hmac username="' + self.app_id + '", ' + \
'algorithm="hmac-sha1", ' + \
'headers="x-date", ' + \
'signature="' + signature + '"'
return {
'Authorization': authorization,
'x-date': format_date_time(mktime(datetime.now().timetuple())),
'Accept - Encoding': 'gzip'
}