mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
Add auth to refresh call
This commit is contained in:
parent
6a201018b1
commit
3fed16d936
2 changed files with 19 additions and 1 deletions
|
|
@ -2,10 +2,23 @@ import os
|
|||
import jwt
|
||||
from flask import request, jsonify
|
||||
from functools import wraps
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
|
||||
SECRET_KEY = os.getenv('JWT_SECRET')
|
||||
ADMIN_SECRET_KEY = os.getenv('JWT_ADMIN_SECRET_KEY')
|
||||
|
||||
def generate_admin_token():
|
||||
expiration_time = datetime.utcnow() + timedelta(minutes=5)
|
||||
payload = {
|
||||
'role': 'admin',
|
||||
'exp': expiration_time
|
||||
}
|
||||
|
||||
token = jwt.encode(payload, ADMIN_SECRET_KEY, algorithm="HS256")
|
||||
return token
|
||||
|
||||
|
||||
def user_token_required(f):
|
||||
@wraps(f)
|
||||
def decorated(*args, **kwargs):
|
||||
|
|
|
|||
|
|
@ -17,10 +17,15 @@ from features.extract import extract_and_upload_raw_data
|
|||
from features.user_history import generate_and_upload_user_history
|
||||
|
||||
from datetime import datetime, timezone
|
||||
from auth import generate_admin_token
|
||||
|
||||
|
||||
def call_refresh_api(api):
|
||||
headers = {
|
||||
'Authorization': f'Bearer {generate_admin_token()}'
|
||||
}
|
||||
try:
|
||||
response = requests.get(api, timeout=10)
|
||||
response = requests.get(api, headers=headers, timeout=10)
|
||||
if response.status_code == 200:
|
||||
print("scoring service refreshed")
|
||||
else:
|
||||
|
|
|
|||
Loading…
Reference in a new issue