MantisBase v0.4.9
Loading...
Searching...
No Matches
realtime_session.h File Reference

Shared auth, topic filtering, and session helpers for SSE and WebSocket realtime. More...

#include <chrono>
#include <set>
#include <string>
#include <string_view>
#include <vector>
#include <drogon/HttpRequest.h>
#include <nlohmann/json.hpp>
#include <mantisbase/core/types.h>
Include dependency graph for realtime_session.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  mb::RealtimeAuthSnapshot
 MbAuth state captured at connect or subscribe time. More...
struct  mb::TopicAccessResult
struct  mb::RealtimeWsSession

Namespaces

namespace  mb

Enumerations

enum class  mb::MbAuthUpgradeResult { mb::Applied , mb::Unchanged , mb::DeniedSwitch , mb::DeniedDowngrade }

Functions

MANTISBASE_API RealtimeAuthSnapshot mb::makeGuestAuthSnapshot ()
MANTISBASE_API std::string mb::resolveRealtimeToken (const drogon::HttpRequestPtr &req)
 Resolve bearer/API-key token from a realtime HTTP upgrade or SSE request.
MANTISBASE_API RealtimeAuthSnapshot mb::resolveRealtimeAuth (const MantisBase &app, const std::string &token)
 Hydrate auth from a JWT or mb_sk_ API key.
MANTISBASE_API TopicAccessResult mb::filterAuthorizedTopics (const MantisBase &app, const std::vector< std::string > &topics, const RealtimeAuthSnapshot &snap)
 Filter topics by entity access rules.
MANTISBASE_API MbAuthUpgradeResult mb::tryUpgradeAuth (RealtimeAuthSnapshot &session, const RealtimeAuthSnapshot &incoming)
 Apply incoming auth to an existing session (subscribe-time upgrade).
MANTISBASE_API std::string mb::generateRealtimeClientId (std::string_view prefix)
 Generate a unique realtime client/session ID.
MANTISBASE_API bool mb::isAuthExpired (const RealtimeAuthSnapshot &snap, const MantisBase &app)
MANTISBASE_API bool mb::isAuthenticatedSnapshot (const RealtimeAuthSnapshot &snap)
MANTISBASE_API void mb::touchWsSession (RealtimeWsSession &session)

Variables

constexpr int mb::kRealtimeNoTopicGraceSeconds = 60
constexpr int mb::kRealtimeIdleTimeoutMinutes = 10
constexpr int mb::kRealtimeCleanupIntervalSeconds = 30

Detailed Description

Shared auth, topic filtering, and session helpers for SSE and WebSocket realtime.

Implements the PocketBase-style two-phase realtime model:

  • Connect: optional credentials; invalid tokens become guest.
  • Subscribe: re-resolve token, upgrade auth, filter topics by entity list/get rules.

Token precedence (realtime only): ?token= query param overrides Authorization: Bearer. Session IDs use the prefixes rt_sse_ and rt_ws_.

See also
sse.h
ws.h
access_rules.h