Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
f5df423
chore(quest): claim quest/m1/auth/bindings-polish.md
kixelated Oct 26, 2026
8bf0ed0
plan(auth): record binding replacement and watch decisions
kixelated Oct 26, 2026
e00511b
Merge remote-tracking branch 'origin/main' into quest/m1/auth/binding…
kixelated Oct 26, 2026
7d81470
plan(auth): propose token replacement and grant watch shapes
kixelated Oct 26, 2026
a395f3c
feat(auth)!: per-connection tokens with an answer, and a grant consumer
kixelated Oct 26, 2026
624f41a
feat(auth)!: wrappers and OBS move to session tokens and grant consumers
kixelated Oct 26, 2026
7ea9747
Merge remote-tracking branch 'origin/main' into quest/m1/auth/binding…
kixelated Oct 26, 2026
21e3324
quest: point request token surfaces at the session token and grant sh…
kixelated Oct 26, 2026
da3b9bc
Merge remote-tracking branch 'origin/main' into worktree-agent-abe648…
kixelated Oct 26, 2026
7021eea
fix(moq-tokio): answer the connection credential by its own verdict
kixelated Oct 26, 2026
beb87b2
Merge origin/main into quest/m1/auth/bindings-polish
kixelated Oct 26, 2026
9aafa28
fix(tokio): build connection Tokens without a transport feature
kixelated Oct 26, 2026
f60b427
fix(moq-tokio): answer kept tokens by their grant on the live session
kixelated Oct 26, 2026
872e881
Merge remote-tracking branch 'origin/main' into iter-6834
kixelated Oct 27, 2026
adae2a0
refactor(auth)!: move per-connection tokens and their answer into moq…
kixelated Oct 27, 2026
1e9fc46
chore(dart): regenerate bindings for the answered doc
kixelated Oct 27, 2026
ef2544f
fix(auth): latch a token set's answer at each peer verdict
kixelated Oct 27, 2026
5938156
fix(auth): accept a moq-lite credential without AUTH only with the se…
kixelated Oct 27, 2026
68c45fc
fix(auth): accept a draft-17+ credential without AUTH only with the s…
kixelated Oct 27, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 2 additions & 25 deletions cpp/obs/src/moq-dock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -728,30 +728,6 @@ void MoQDock::PeelJwtFromRelayUrl()
urlEdit->setText(url.toString());
}

QString MoQDock::ConnectUrl() const
{
QString text = urlEdit->text().trimmed();
const QString token = tokenEdit->text().trimmed();
if (token.isEmpty())
return text;

QUrl url(text);
if (!url.isValid() || url.scheme().isEmpty()) {
// Cannot confirm the transport is encrypted, so do not attach the token.
return text;
}

// Never put a JWT on cleartext network dial URLs.
if (MoQDial::IsCleartext(url.scheme().toStdString()))
return text;

QUrlQuery query(url);
query.removeAllQueryItems("jwt");
query.addQueryItem("jwt", token);
url.setQuery(query);
return url.toString();
}

void MoQDock::OnEncodingChanged(int mode)
{
const bool enabled = mode == 1;
Expand Down Expand Up @@ -1098,7 +1074,7 @@ void MoQDock::StartStream()
}
}

const std::string url = ConnectUrl().toStdString();
const std::string url = relayText.toStdString();
const std::string path = pathEdit->text().toStdString();
tokenEdited = false;
tokenNotice.clear();
Expand All @@ -1113,6 +1089,7 @@ void MoQDock::StartStream()
obs_data_apply(serviceSettings, advanced);
obs_data_set_string(serviceSettings, "server", url.c_str());
obs_data_set_string(serviceSettings, "key", path.c_str());
obs_data_set_string(serviceSettings, "bearer_token", token.toStdString().c_str());
service =
OBSServiceAutoRelease(obs_service_create("moq_service", "moq_dock_service", serviceSettings, nullptr));
if (!service) {
Expand Down
1 change: 0 additions & 1 deletion cpp/obs/src/moq-dock.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ private slots:
bool CreateConfiguredEncoders();
bool CreateCustomEncoders();
void CreateVideoEncoder(const char *id, obs_data_t *settings);
QString ConnectUrl() const;
void PeelJwtFromRelayUrl();
void ClearLiveStats();

Expand Down
52 changes: 31 additions & 21 deletions cpp/obs/src/moq-output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,11 @@ bool MoQOutput::Start()
moq::ClientConfig config;
config.publish = next_origin;
config.implementation = MoQImplementation();
// Not on the URL: a URL's ?jwt= overrides the client's tokens, so every reconnect
// would dial it instead of the one PresentToken() set last.
if (const char *token = obs_service_get_connect_info(service, OBS_SERVICE_CONNECT_INFO_BEARER_TOKEN);
token && *token)
config.tokens = {token};
OBSDataAutoRelease service_settings = obs_service_get_settings(service);
std::string invalid = MoQSettings::Configure(service_settings, config);
std::shared_ptr<moq::Client> client;
Expand Down Expand Up @@ -528,31 +533,36 @@ bool MoQOutput::PresentToken(const std::string &token)
std::lock_guard<std::recursive_mutex> signal_lock(signal_mutex);
if (!attempt || !attempt->session)
return false;
// Only a server-accepted session has no tokens.
std::shared_ptr<moq::Tokens> tokens = attempt->session->tokens();
if (!tokens)
return false;

auto refused = [this](const std::string &reason) {
LOG_WARNING("MoQ relay refused the new publish token: %s", reason.c_str());
std::lock_guard<std::mutex> lock(mutex);
token_refusal = reason;
};
{
std::lock_guard<std::mutex> lock(mutex);
token_refusal.clear();
}

// Replacing `presenting` cancels a presentation still in flight, which the
// newer token supersedes.
attempt->presenting = attempt->session->auth()->add(token).then(
worker.Executor(), Current<moq::expected<std::shared_ptr<moq::AuthToken>>>(
attempt, [this](const std::shared_ptr<Attempt> &current, auto result) {
if (!result) {
const std::string reason = result.error().to_string();
LOG_WARNING("MoQ relay refused the new publish token: %s",
reason.c_str());
std::lock_guard<std::mutex> lock(mutex);
token_refusal = reason;
return;
}
// The old token's grant leaves the union only after the new one joined.
if (current->token)
current->token->cancel();
current->token = *result;
LOG_INFO("MoQ relay accepted the new publish token: %s",
MoQRedactUrl(current->url).c_str());
}));
if (auto set = tokens->set({token}); !set) {
attempt->presenting.reset();
refused(set.error().to_string());
return true;
}

// Replacing `presenting` drops the wait on a token this one replaced.
attempt->presenting = tokens->answered().then(
worker.Executor(),
Current<moq::expected<void>>(attempt, [refused](const std::shared_ptr<Attempt> &current, auto result) {
if (!result) {
refused(result.error().to_string());
return;
}
LOG_INFO("MoQ relay accepted the new publish token: %s", MoQRedactUrl(current->url).c_str());
}));
return true;
}

Expand Down
13 changes: 5 additions & 8 deletions cpp/obs/src/moq-output.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,10 @@ class MoQOutput {
};
bool TryGetVideoRate(VideoRate *out);

// Present a fresh publish token on the connected session without reconnecting,
// replacing the one presented here before once the relay accepts it. False when
// there is no session yet. The outcome is logged, and a refusal is kept for
// TokenRefusal(); a session without in-band AUTH refuses it.
// Replace the session's tokens with a fresh publish token, presented without
// reconnecting and on every reconnect; the one it replaces is withdrawn once the
// relay answers. False when there is no session yet. The answer is logged, and a
// refusal is kept for TokenRefusal(); a session without in-band AUTH refuses it.
bool PresentToken(const std::string &token);
// Why the relay refused the token PresentToken() last presented, or empty.
std::string TokenRefusal();
Expand All @@ -104,10 +104,7 @@ class MoQOutput {
bool connected = false;
// False while the session is between reconnects.
bool live = false;
// The latest token PresentToken() got accepted, presented on every reconnect
// until it is replaced or the attempt is dropped, and the call presenting the
// next one.
std::shared_ptr<moq::AuthToken> token;
// The wait for the relay's answer to the token PresentToken() set last.
std::optional<moq::Continuation> presenting;
};

Expand Down
5 changes: 4 additions & 1 deletion cpp/obs/src/moq-service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
const char *audio_codecs[] = {"aac", "opus", nullptr};
const char *video_codecs[] = {"h264", "hevc", "av1", nullptr};

MoQService::MoQService(obs_data_t *settings, obs_service_t *) : server(), path()
MoQService::MoQService(obs_data_t *settings, obs_service_t *) : server(), path(), token()
{
Update(settings);
}
Expand All @@ -15,6 +15,7 @@ void MoQService::Update(obs_data_t *settings)
{
server = obs_data_get_string(settings, "server");
path = obs_data_get_string(settings, "key");
token = obs_data_get_string(settings, "bearer_token");
}

obs_properties_t *MoQService::Properties()
Expand Down Expand Up @@ -58,6 +59,8 @@ const char *MoQService::GetConnectInfo(enum obs_service_connect_info type)
return server.c_str();
case OBS_SERVICE_CONNECT_INFO_STREAM_KEY:
return path.c_str();
case OBS_SERVICE_CONNECT_INFO_BEARER_TOKEN:
return token.empty() ? nullptr : token.c_str();
default:
return nullptr;
}
Expand Down
2 changes: 2 additions & 0 deletions cpp/obs/src/moq-service.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ struct MoQService {
// TODO: Define needed params to connect to a relay
std::string server;
std::string path;
// The dock's publish token, which the output presents through the client's tokens.
std::string token;

MoQService(obs_data_t *settings, obs_service_t *service);

Expand Down
4 changes: 2 additions & 2 deletions cpp/obs/test/moq-output-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -873,8 +873,8 @@ int main()
}
printf("OBS-driven restart: ok\n");

// A token edited mid-stream goes to the live session only, and presenting a
// newer one or stopping cancels whatever is still in flight.
// A token edited mid-stream replaces the session's tokens, and presenting a
// newer one or stopping drops the wait on the relay's answer still in flight.
{
TestRelay relay;
reset(relay.Url());
Expand Down
2 changes: 1 addition & 1 deletion dart/moq/MIGRATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ the matching generated bindings and native library.
### Cancelling a stream cancels its pending read

`await subscription.cancel()` on announcements, authorization grants, and server requests now waits for the pending native operation to release, even when no event arrives.
Announcement subscriptions still own and release their cursor; cancelling a grant or request subscription keeps its shared `Auth` or `Server` usable.
Announcement and grant subscriptions own and release their consumer; cancelling a request subscription keeps its shared `Server` usable.
The generated async methods now return `UniffiRustFuture<T>`, a `Future<T>` with `cancel()`; existing `await` and `Future<T>` assignments work unchanged.
Custom implementations of generated interfaces must return `UniffiRustFuture<T>` instead of a plain `Future<T>`.

Expand Down
7 changes: 2 additions & 5 deletions dart/moq/lib/src/aliases.dart
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,8 @@ typedef Reservation = MoqReservation;
/// A snapshot of transport connection statistics.
typedef ConnectionStats = MoqConnectionStats;

/// A session's authorization: the grant its peer gave it, and more tokens to present.
typedef Auth = MoqAuth;

/// One token presented with [Auth.add]; cancel it to withdraw the token.
typedef AuthToken = MoqAuthToken;
/// Follows the grant a session's peer gave it; cancel it to release a pending wait.
typedef GrantConsumer = MoqGrantConsumer;

/// What the peer lets this side do: publish and subscribe patterns, and an expiry.
typedef Grant = MoqGrant;
Expand Down
42 changes: 25 additions & 17 deletions dart/moq/lib/src/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -244,12 +244,11 @@ final class Moq {
/// the room back.
Bandwidth bandwidth() => session.bandwidth();

/// The session's authorization: the grant its peer gave it, and more tokens to present.
/// Follow the grant the peer gave this session.
///
/// Listen to [AuthGrants.grants] to follow the grant, and [Auth.add] a fresh
/// token before the current one expires; each added token is presented again
/// on every reconnect.
Auth auth() => session.auth();
/// Listen to [GrantConsumerUpdates.updates] for the current grant and each
/// change. Every call returns an independent consumer.
GrantConsumer grants() => session.grants();

/// The credentials every dial presents ([ConnectOptions.tokens]), to
/// replace while running.
Expand All @@ -258,9 +257,9 @@ final class Moq {
/// next dial presents them, and a live session with in-band AUTH presents
/// them at once, withdrawing each replaced token once its replacements are
/// answered, even when one is refused. After an authorization refusal the
/// client redials only if they changed. An empty token throws
/// `ConfigMoqException`.
Tokens tokens() => _client.tokens();
/// session redials only if they changed. An empty token throws
/// `ConfigMoqException`. Await [Tokens.answered] for the relay's verdict.
Tokens tokens() => session.tokens()!;

/// Drain within one second, then stop the client.
///
Expand All @@ -278,13 +277,13 @@ final class Moq {
}

/// A [Stream] view over a session's grant.
extension AuthGrants on Auth {
extension GrantConsumerUpdates on GrantConsumer {
/// The current grant, then each change, null while there is none.
///
/// Listens on one [Auth] share its place in the changes, so a second watcher
/// takes its own from [Moq.auth]. Cancelling releases only its pending read.
/// Ends when the session shuts down, and errors with its close reason otherwise.
Stream<Grant?> grants() => _Grants(this);
/// Listen once: the consumer is cancelled and released when the subscription
/// ends. Ends when the session shuts down, and errors with its close reason
/// otherwise.
Stream<Grant?> updates() => _Grants(this);
}

/// A [Stream] view over an announcement cursor.
Expand All @@ -297,18 +296,27 @@ extension AnnounceConsumerUpdates on AnnounceConsumer {
}

final class _Grants extends NativeStream<Grant?> {
final Auth auth;
_Grants(this.auth);
final GrantConsumer grants;
_Grants(this.grants);

@override
Iterable<Grant?> initial() => [auth.grant()];
Iterable<Grant?> initial() => [grants.grant()];

@override
UniffiRustFuture<Grant?> read() => auth.grantChanged();
UniffiRustFuture<Grant?> read() => grants.changed();

@override
bool ended(Object error) =>
error is CancelledMoqException || error is ClosedMoqException;

@override
void release() {
try {
grants.cancel();
} finally {
grants.dispose();
}
}
}

final class _Updates extends NativeStream<AnnounceEvent?> {
Expand Down
19 changes: 11 additions & 8 deletions dart/moq/test/cancellation_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -89,19 +89,22 @@ final class _Announcements implements AnnounceConsumer {
dynamic noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
}

final class _Auth implements Auth {
final class _Grants implements GrantConsumer {
final started = Completer<_Read<Grant?>>();
var cancels = 0;
var disposals = 0;

@override
Grant? grant() => null;
@override
UniffiRustFuture<Grant?> grantChanged() {
UniffiRustFuture<Grant?> changed() {
final read = _Read<Grant?>();
started.complete(read);
return read;
}

@override
void cancel() => cancels++;
@override
void dispose() => disposals++;
@override
Expand All @@ -125,17 +128,17 @@ void main() {
},
);

test('idle grant cancellation leaves the shared auth usable', () async {
final auth = _Auth();
test('idle grant cancellation releases its read and consumer', () async {
final source = _Grants();
final grants = <Grant?>[];
final subscription = auth.grants().listen(grants.add);
final read = await auth.started.future;
final subscription = source.updates().listen(grants.add);
final read = await source.started.future;
await subscription.cancel();
expect(grants, [null]);
expect(read.cancels, 1);
expect(read.cleaned.isCompleted, isTrue);
expect(auth.disposals, 0);
expect(auth.grant(), isNull);
expect(source.cancels, 1);
expect(source.disposals, 1);
});

test('cancellation before the first read still releases ownership', () async {
Expand Down
10 changes: 6 additions & 4 deletions dart/moq/test/moq_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -183,25 +183,27 @@ void main() {

expectEverything(
await client
.auth()
.grants()
.updates()
.firstWhere((g) => g != null)
.timeout(timeout),
);
expectEverything(
await serverSession
.auth()
.grants()
.updates()
.firstWhere((g) => g != null)
.timeout(timeout),
);
expect(serverSession.tokens(), isNull);

// A peer that verifies no tokens of its own refuses another one.
client.tokens().set_(tokens: ['extra']);
await expectLater(
client.auth().add(token: 'extra').timeout(timeout),
client.tokens().answered().timeout(timeout),
throwsA(isA<UnsupportedMoqException>()),
);
expectEverything(client.auth().grant());
expectEverything(client.grants().grant());

// The client drains first: cancelling the server session would fail its shutdown.
await client.close();
Expand Down
Loading
Loading