68 lines
2.2 KiB
Python
68 lines
2.2 KiB
Python
"""
|
|
Controller for token validation endpoints.
|
|
"""
|
|
from flask import Blueprint, request, jsonify
|
|
from app.middleware import api_key_required
|
|
from app.models import ValidateTokenRequest, ValidateTokenResponse
|
|
import logging
|
|
|
|
# Configure logger
|
|
logger = logging.getLogger(__name__)
|
|
|
|
# Create blueprint
|
|
token_bp = Blueprint('token', __name__)
|
|
|
|
@token_bp.route('/ValidateToken', methods=['POST'])
|
|
@api_key_required
|
|
def validate_token():
|
|
"""
|
|
Endpoint to validate user authentication tokens.
|
|
|
|
This method is used when users from FirstBank access the Customer Care Portal.
|
|
It validates the soft/hard token code entered by the user.
|
|
|
|
Returns:
|
|
JSON response with token validation results
|
|
"""
|
|
try:
|
|
# Parse and validate request
|
|
data = request.get_json()
|
|
if not data:
|
|
return jsonify({
|
|
'resultCode': '400',
|
|
'resultDescription': 'Invalid JSON payload'
|
|
}), 400
|
|
|
|
# Validate required fields
|
|
required_fields = ['RequestId', 'UserId', 'CountryId', 'TokenCode']
|
|
for field in required_fields:
|
|
if field not in data:
|
|
return jsonify({
|
|
'resultCode': '422',
|
|
'resultDescription': f'Missing required field: {field}'
|
|
}), 422
|
|
|
|
# Create request model
|
|
req = ValidateTokenRequest.from_dict(data)
|
|
|
|
# Process token validation (this would connect to the business logic)
|
|
# For demonstration, we'll return a mock response with successful validation
|
|
|
|
# Create response
|
|
response = ValidateTokenResponse(
|
|
Authenticated=True,
|
|
AuthenticatedMessage=f"The user with ID {req.UserId} has successfully authenticated!",
|
|
ResponseCode="00",
|
|
ResponseMessage="Successful",
|
|
RequestId=req.RequestId
|
|
)
|
|
|
|
logger.info(f"Processed token validation for user {req.UserId}")
|
|
return jsonify(response.to_dict())
|
|
|
|
except Exception as e:
|
|
logger.error(f"Error processing token validation: {str(e)}")
|
|
return jsonify({
|
|
'resultCode': '500',
|
|
'resultDescription': 'Internal server error'
|
|
}), 500 |