Short-lived Avatar Tokens (Advanced)
Use the Backend-for-Frontend (BFF) pattern when you want your own backend to fetch short-lived Sentifyd access tokens and hand them to the browser on demand. This keeps API keys and refresh tokens of
When should I use this?
1 — Add an endpoint in your backend
Reference endpoint implementation
from flask import Blueprint, current_app, jsonify, request
import requests
blueprint = Blueprint("sentifyd", __name__)
@blueprint.route("/request_tokens", methods=["GET"])
def request_tokens():
sentifyd_backend_url = current_app.config["SENTIFYD_BACKEND"] + "/api/login"
avatar_api_key = current_app.config["AVATAR_API_KEY"]
payload = {"avatar_api_key": avatar_api_key}
try:
response = requests.post(sentifyd_backend_url, json=payload)
if response.status_code != 200:
return jsonify({"error": "Authentication failed", "details": response.json()}), response.status_code
data = response.json()["data"]
frontend_payload = {
"tokens": {
"accessToken": data["access_token"],
"refreshToken": data["refresh_token"],
},
"avatarParameters": data["avatar_params"],
}
return jsonify(frontend_payload), 200
except Exception as e:
current_app.logger.exception("Error while requesting Sentifyd tokens")
return jsonify({"error": "Internal server error"}), 5002 — Serve the Sentifyd web component
3 — How it works
4 — Minimal example (static HTML)
Last updated