admin管理员组

文章数量:1391943

@pubsub_bp.route("/api/pubsub/events", methods=["POST"])
def handle_pubsub_event():
    try:
        print("Received Pub/Sub event")
        envelope = request.get_json()
        if not envelope or 'message' not in envelope:
            return "Invalid Pub/Sub message format", 400

        pubsub_message = envelope['message']
        data = pubsub_message.get('data')

        if data:
            # Decode base64 message
            decoded_data = base64.b64decode(data).decode("utf-8")
            message_json = json.loads(decoded_data)

            # Extract account_id and entitlements
            account_id = message_json.get("account_id")
            entitlements = message_json.get("entitlements", [])

            print(f"Received Pub/Sub message: account_id={account_id}, entitlements={entitlements}")

            # ⚡ Approve the account in your system (Firebase example)
            if account_id:
                db.collection("accounts").document(account_id).set({
                    "status": "approved",
                    "entitlements": entitlements
                }, merge=True)

                print(f"Account {account_id} marked as approved in Firebase.")

            return "OK", 200

        return "No data in Pub/Sub message", 400

    except Exception as e:
        print(f"Error processing Pub/Sub event: {str(e)}")
        return f"Error: {str(e)}", 500

This is how I am listening to pub sub push url. Not sure how I can approve users and entitlements. Some code snippet will be helpful

本文标签: