- Introduction of API-functionality (to be continued). Deduplication of document and url uploads between views and api. - Improvements on document processing - introduction of processor classes to streamline document inputs - Removed pure Youtube functionality, as Youtube retrieval of documents continuously changes. But added upload of srt, mp3, ogg and mp4
25 lines
928 B
Python
25 lines
928 B
Python
from flask_restful import Resource, reqparse
|
|
from flask_jwt_extended import create_access_token
|
|
from common.models.user import Tenant
|
|
from common.extensions import simple_encryption
|
|
from flask import current_app
|
|
|
|
|
|
class TokenResource(Resource):
|
|
def post(self):
|
|
parser = reqparse.RequestParser()
|
|
parser.add_argument('tenant_id', type=int, required=True)
|
|
parser.add_argument('api_key', type=str, required=True)
|
|
args = parser.parse_args()
|
|
|
|
tenant = Tenant.query.get(args['tenant_id'])
|
|
if not tenant:
|
|
return {'message': 'Tenant not found'}, 404
|
|
|
|
decrypted_api_key = simple_encryption.decrypt_api_key(tenant.encrypted_api_key)
|
|
if args['api_key'] != decrypted_api_key:
|
|
return {'message': 'Invalid API key'}, 401
|
|
|
|
access_token = create_access_token(identity={'tenant_id': tenant.id})
|
|
return {'access_token': access_token}, 200
|