-
|
Hi everyone, I am trying to implement a type of custom authentication by using class CustomAuth(AuthBase):
def __init__(self, secretkey):
self.secretkey = secretkey
def get_hash(self, request):
if request.body:
data = request.body.decode('utf-8')
else:
data = "{}"
signature = hmac.new(
str.encode(self.secretkey),
msg=str.encode(data),
digestmod=hashlib.sha256
).hexdigest().upper()
return signature
def __call__(self, request):
request.headers["CUSTOM-AUTH"] = self.get_hash(request)
return requestI've looked into tracing and BasicAuth but they are useless in my situation. On Do you have any idea? Thanks in advance. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
|
i have this problem too. |
Beta Was this translation helpful? Give feedback.
-
|
hi @byildiz |
Beta Was this translation helpful? Give feedback.
-
|
I think I should write my workaround as an answer: I solved my problem by using Line 205 in ed19689 You can call json.dumps on the data that you want to sent and you will get the exactly same body with the body aiohttp will create.
|
Beta Was this translation helpful? Give feedback.
I think I should write my workaround as an answer:
I solved my problem by using
json.dumpssince aiohttp internally usesjson.dumpsto convert json data to http body by default. Here it is:aiohttp/aiohttp/client.py
Line 205 in ed19689
You can call
json.dumpson the data that you want to sent and you will get the exactly same body with the body aiohttp will create.