- Furter refinement of the API, adding functionality for refreshing documents and returning Token expiration time when retrieving token

- Implementation of a first version of a Wordpress plugin
- Adding api service to nginx.conf
This commit is contained in:
Josako
2024-09-11 16:31:13 +02:00
parent 76cb825660
commit 9e14824249
17 changed files with 997 additions and 19 deletions

View File

@@ -1,3 +1,5 @@
from datetime import timedelta
from flask_restx import Namespace, Resource, fields
from flask_jwt_extended import create_access_token
from common.models.user import Tenant
@@ -12,7 +14,8 @@ token_model = auth_ns.model('Token', {
})
token_response = auth_ns.model('TokenResponse', {
'access_token': fields.String(description='JWT access token')
'access_token': fields.String(description='JWT access token'),
'expires_in': fields.Integer(description='Token expiration time in seconds')
})
@@ -56,11 +59,17 @@ class Token(Resource):
current_app.logger.error(f"Invalid API key for tenant: {tenant_id}")
return {'message': "Invalid API key"}, 401
# Get the JWT_ACCESS_TOKEN_EXPIRES setting from the app config
expires_delta = current_app.config.get('JWT_ACCESS_TOKEN_EXPIRES', timedelta(minutes=15))
try:
current_app.logger.debug(f"Creating access token for tenant: {tenant_id}")
access_token = create_access_token(identity=tenant_id)
access_token = create_access_token(identity=tenant_id, expires_delta=expires_delta)
current_app.logger.debug("Access token created successfully")
return {'access_token': access_token}, 200
return {
'access_token': access_token,
'expires_in': expires_delta.total_seconds()
}, 200
except Exception as e:
current_app.logger.error(f"Error creating access token: {e}")
return {'message': "Internal server error"}, 500