Skip to content

Commit 51182a2

Browse files
author
openclaw-bot
committed
chore: fallback to basic auth when bearer token is absent
1 parent 4ed4065 commit 51182a2

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

‎bootpay_backend/rest_client.py‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import requests
22
import urllib.parse
3+
import base64
34

45

56
class BootpayBackend:
@@ -33,18 +34,25 @@ def set_api_version(self, version):
3334
# @param method: string, url: string, data: object, headers: object
3435
# @returns ResponseForamt
3536
def __request(self, method='', url='', data=None, headers={}, params={}):
37+
auth_header = None
38+
if self.token is not None:
39+
auth_header = f"Bearer {self.token}"
40+
elif self.application_id and self.private_key:
41+
encoded = base64.b64encode(f"{self.application_id}:{self.private_key}".encode('utf-8')).decode('utf-8')
42+
auth_header = f"Basic {encoded}"
43+
3644
if method in ['put', 'post']:
3745
response = getattr(requests, method)(url, json=data, headers=dict(headers, **{
3846
'Accept': 'application/json',
39-
'Authorization': (None if self.token is None else f"Bearer {self.token}"),
47+
'Authorization': auth_header,
4048
'BOOTPAY-API-VERSION': self.api_version,
4149
'BOOTPAY-SDK-VERSION': self.SDK_VERSION,
4250
'BOOTPAY-SDK-TYPE': '302'
4351
}), params=params)
4452
else:
4553
response = getattr(requests, method)(url, headers=dict(headers, **{
4654
'Accept': 'application/json',
47-
'Authorization': (None if self.token is None else f"Bearer {self.token}")
55+
'Authorization': auth_header
4856
}), params=params)
4957
return response.json()
5058

0 commit comments

Comments
 (0)