Skip to content

Commit

Permalink
jwt token check (#700)
Browse files Browse the repository at this point in the history
  • Loading branch information
JoinTyang authored Dec 9, 2024
1 parent c5f527d commit 0f1c164
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions dtable_events/utils/dtable_web_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def run_script(self, dtable_uuid, script_name, context_data, owner, org_id, scri
'operator': operator
}, headers=headers, timeout=10)
return parse_response(response)

def get_users_common_info(self, user_id_list):
url = self.dtable_web_service_url + '/api/v2.1/users-common-info/'
json_data = {
Expand All @@ -179,15 +179,18 @@ def internal_add_notification(self, to_users, msg_type, detail):
url = '%(server_url)s/api/v2.1/internal-notifications/?from=dtable_events' % {
'server_url': self.dtable_web_service_url
}
token = jwt.encode({}, DTABLE_PRIVATE_KEY, algorithm='HS256')
payload = {
'exp': int(time.time()) + 60
}
token = jwt.encode(payload, DTABLE_PRIVATE_KEY, algorithm='HS256')
headers = {'Authorization': 'Token ' + token}
resp = requests.post(url, json={
'detail': detail,
'to_users': to_users,
'type': msg_type
}, headers=headers)
return parse_response(resp)

def internal_submit_row_workflow(self, workflow_token, row_id, rule_id=None):
logger.debug('internal submit row workflow token: %s row_id: %s rule_id: %s', workflow_token, row_id, rule_id)
url = '%(server_url)s/api/v2.1/workflows/%(workflow_token)s/internal-task-submit/' % {
Expand All @@ -201,6 +204,10 @@ def internal_submit_row_workflow(self, workflow_token, row_id, rule_id=None):
}
if rule_id:
data['automation_rule_id'] = rule_id
header_token = 'Token ' + jwt.encode({'token': workflow_token}, DTABLE_PRIVATE_KEY, 'HS256')
payload = {
'exp': int(time.time()) + 60,
'token': workflow_token
}
header_token = 'Token ' + jwt.encode(payload, DTABLE_PRIVATE_KEY, 'HS256')
resp = requests.post(url, data=data, headers={'Authorization': header_token}, timeout=30)
return parse_response(resp)

0 comments on commit 0f1c164

Please sign in to comment.