Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jwt token check #700

Merged
merged 1 commit into from
Dec 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)