This document outlines the requirements for implementing a custom token validation endpoint that integrates with Miri's authentication system.
The custom token validation endpoint is used to validate authentication tokens and retrieve user information. This endpoint must be implemented by companies wishing to integrate their authentication system with Miri.
{
"token": "string" // The token to be validated
}
{
"token": "string", // The token to be validated
"authorization_request": {
"entries": [
{
"external_uid": "string" // External user ID only
}
]
}
}
Important: The authorization request only includes external_uid values. The system will set default permissions and expiration times internally. Your endpoint should only validate that the authenticated user has permission to grant access to these external user IDs.
{
"sub": "string", // Required: The external user ID
// Additional fields can be included in the response
}
{
"sub": "string", // Required: The external user ID
"authorization_request": {
"entries": [
{
"external_uid": "string" // Validated external user ID only
}
]
}
// Additional fields can be included in the response
}
sub field is mandatory and must contain the external user IDexternal_uid valuesWhen an authorization request is included in the token validation request, your endpoint should:
{
"sub": "user123",
"email": "user@example.com",
"name": "John Doe"
}
{
"sub": "admin456",
"email": "admin@company.com",
"name": "Admin User",
"authorization_request": {
"entries": [
{
"external_uid": "user123"
}
]
}
}
{
"error": "Invalid token",
"message": "Token has expired"
}
{
"error": "Authorization validation failed",
"message": "User does not have permission to grant access to external_uid: user789"
}
When using the miri-react-native-sdk with custom token validation:
provider: "custom" in your MiriAuth configurationauthorization_request in your config for secure authorization processingfrom flask import Flask, request, jsonify
from datetime import datetime, timedelta
app = Flask(__name__)
@app.route('/validate', methods=['POST'])
def validate_token():
data = request.get_json()
token = data.get('token')
authorization_request = data.get('authorization_request')
# Validate the token (your existing logic)
if not is_valid_token(token):
return jsonify({"error": "Invalid token"}), 401
# Extract user info from token
user_info = extract_user_from_token(token)
# Validate authorization request if present
if authorization_request:
try:
validated_auth = validate_authorization_request(user_info, authorization_request)
except ValueError as e:
return jsonify({"error": "Authorization validation failed", "message": str(e)}), 403
return jsonify({
"sub": user_info['user_id'],
"email": user_info['email'],
"name": user_info['name'],
"authorization_request": validated_auth
})
# Basic response without authorization
return jsonify({
"sub": user_info['user_id'],
"email": user_info['email'],
"name": user_info['name']
})
def validate_authorization_request(user_info, auth_request):
"""Validate the authorization request against user permissions."""
# Check if user has permission to grant access
if not has_authorization_permission(user_info):
raise ValueError("User does not have authorization permission")
# Validate each entry
for entry in auth_request['entries']:
external_uid = entry['external_uid']
# Check if user can access this external user
if not can_access_external_user(user_info, external_uid):
raise ValueError(f"User cannot access external_uid: {external_uid}")
# Return validated authorization request with only external_uid values
return {
"entries": [
{"external_uid": entry["external_uid"]}
for entry in auth_request['entries']
]
}