Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
df12a51
feat(relay): self-hosted T3 Connect relay with OIDC sign-in (WIP)
TuroYT Nov 7, 2026
1ec1f96
feat(connect): choose a self-hosted relay in settings
TuroYT Nov 8, 2026
c318441
fix(relay): self-hosted relay accepts DPoP proofs behind a TLS proxy
TuroYT Nov 10, 2026
a665036
feat(relay): carry environments over a relay channel without a tunnel
TuroYT Nov 10, 2026
dd82dfa
fix(relay): bind relay channels to the environment key and drop revok…
TuroYT Nov 10, 2026
9084db5
feat(relay): serve relay channels under /env/<key> instead of subdomains
TuroYT Nov 10, 2026
ffea460
fix(relay): keep relay channel responses from acting on the relay origin
TuroYT Nov 10, 2026
39f6878
fix(relay): filter relay channel response headers case-insensitively
TuroYT Nov 10, 2026
23bbd87
fix(relay): allowlist response headers from relay channel environments
TuroYT Nov 10, 2026
137386a
fix(relay): reconnect relay channels the relay silently dropped
TuroYT Nov 10, 2026
5bd54c6
feat(connect): deregister environments from a self-hosted relay account
TuroYT Nov 10, 2026
a938d26
fix(connect): label relay-carried environments on the account page
TuroYT Nov 10, 2026
4e1f5c6
fix(connect): self-hosted relay account page loads, and removal dereg…
TuroYT Nov 10, 2026
ff03b4c
fix(mobile): self-hosted sign-in works on Android without Web Crypto
TuroYT Nov 10, 2026
224b5ef
fix(connect): harden relay channels and OIDC sign-in after review
TuroYT Nov 11, 2026
be25dc8
fix(relay): keep carried PDFs sandboxed on the relay origin
TuroYT Nov 11, 2026
2974568
fix(connect): clear typecheck failures and a stale Clerk mock
TuroYT Nov 11, 2026
c0459a7
fix(connect): address the relay review findings
TuroYT Nov 11, 2026
b6f436f
fix(connect): address the second relay review
TuroYT Nov 11, 2026
39eed46
Merge remote-tracking branch 'github/main' into t3/self-hosted-connec…
maria-rcks Nov 11, 2026
f4947bf
fix(connect): keep relay channel readiness current and public key rea…
maria-rcks Nov 11, 2026
d4261ff
Merge remote-tracking branch 'upstream/main' into t3code/pr-34302/t3/…
TuroYT Nov 14, 2026
60b530f
fix(connect): address the third relay review
TuroYT Nov 14, 2026
9ac177c
fix(mobile): blank the OIDC session when SecureStore cannot delete it
TuroYT Nov 14, 2026
fcd681a
fix(connect): describe publish-only relay access accurately
maria-rcks Nov 15, 2026
f6d3c4d
fix(connect): send PKCE with the headless device sign-in
TuroYT Nov 15, 2026
c1ebbef
Merge upstream/main into t3/self-hosted-connect-service
TuroYT Nov 15, 2026
8d808e1
fix(connect): declare Digest for the CLI device sign-in
TuroYT Nov 15, 2026
5e2523a
Merge branch 'main' into t3/self-hosted-connect-service
TuroYT Nov 16, 2026
b685f62
Merge remote-tracking branch 'upstream/main' into pr34302-merge
TuroYT Nov 18, 2026
c388320
fix(connect): translate the self-hosted relay and OIDC copy
TuroYT Nov 18, 2026
2239610
Merge remote-tracking branch 'github/main' into takeover-34302
maria-rcks Nov 18, 2026
b8787c3
fix(relay): show the provider's reason on token errors, document Entr…
TuroYT Nov 18, 2026
dc34ad0
fix(server): startup log no longer prints a stale relay URL
TuroYT Nov 18, 2026
c417cb8
fix(relay): the self-host image no longer ships node_modules
TuroYT Nov 18, 2026
33ef5ca
Merge upstream/main into self-hosted-connect-service
TuroYT Nov 19, 2026
8312715
Merge upstream/main into self-hosted-connect-service
TuroYT Nov 20, 2026
fc23516
Merge upstream/main into self-hosted-connect-service
TuroYT Nov 21, 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
12 changes: 12 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
**/node_modules
.git
.t3
.repos
.env
.env.*
**/.env
infra/relay/selfhost/secrets
infra/relay/selfhost/.env
**/dist
**/dist-*
**/*.log
21 changes: 19 additions & 2 deletions apps/desktop/src/app/DesktopClerk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { codexAuthDeliveryUrl, readCodexAuthHandoff } from "@t3tools/shared/code
import { receiveCodexAuthCallback, CodexAuthCallbackError } from "./CodexAuthCallback.ts";
import * as ElectronShell from "../electron/ElectronShell.ts";
import { providerAuthReturnUrl } from "@t3tools/shared/providerAuthReturnUrl";
import { isDesktopOidcCallbackUrl } from "@t3tools/shared/oidc";
import { promptLinkAppPath } from "@t3tools/shared/promptLinks";
import { readPairingAppLink } from "@t3tools/shared/remote";
import * as HostProcess from "@t3tools/shared/HostProcess";
Expand Down Expand Up @@ -216,9 +217,25 @@ export const make = Effect.gen(function* () {
return true;
};
const openAppLink = (value: string | undefined) => {
if (!value || (promptLinkAppPath(value) === null && readPairingAppLink(value) === null))
if (
!value ||
(promptLinkAppPath(value) === null &&
readPairingAppLink(value) === null &&
!isDesktopOidcCallbackUrl(value))
)
return false;
void runPromise(webLinks.receive(value));
void runPromise(
webLinks.receive(value).pipe(
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
Effect.andThen(
Effect.gen(function* () {
// The identity provider left the user in the system browser.
if (!isDesktopOidcCallbackUrl(value)) return;
const mainWindow = yield* electronWindow.currentMainOrFirst;
if (Option.isSome(mainWindow)) yield* electronWindow.reveal(mainWindow.value);
}),
),
),
);
return true;
};
const args = yield* HostProcess.Arguments;
Expand Down
4 changes: 4 additions & 0 deletions apps/mobile/app.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,10 @@ const config: ExpoConfig = {
publishableKey: repoEnv.EXPO_PUBLIC_CLERK_PUBLISHABLE_KEY ?? null,
jwtTemplate: repoEnv.EXPO_PUBLIC_CLERK_JWT_TEMPLATE ?? null,
},
oidc: {
issuer: repoEnv.EXPO_PUBLIC_OIDC_ISSUER ?? null,
clientId: repoEnv.EXPO_PUBLIC_OIDC_CLIENT_ID ?? null,
},
// Clerk reads these exact names at prebuild. Omit unset values: manifest null becomes truthy {}.
EXPO_PUBLIC_CLERK_GOOGLE_WEB_CLIENT_ID: repoEnv.EXPO_PUBLIC_CLERK_GOOGLE_WEB_CLIENT_ID,
EXPO_PUBLIC_CLERK_GOOGLE_IOS_CLIENT_ID: repoEnv.EXPO_PUBLIC_CLERK_GOOGLE_IOS_CLIENT_ID,
Expand Down
6 changes: 6 additions & 0 deletions apps/mobile/src/Stack.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ import { UsageLimitAccountScreen } from "./features/usage/UsageLimitsPooled";
import { UsageRouteScreen } from "./features/usage/UsageRouteScreen";
import { SettingsAboutRouteScreen } from "./features/settings/SettingsAboutRouteScreen";
import { SettingsNotificationsRouteScreen } from "./features/settings/SettingsNotificationsRouteScreen";
import { SettingsConnectServiceRouteScreen } from "./features/settings/SettingsConnectServiceRouteScreen";
import { SettingsRouteScreen } from "./features/settings/SettingsRouteScreen";
import { SettingsLabsRouteScreen } from "./features/settings/ThreadSettingsSections";
import { SettingsEnvironmentFilterProvider } from "./features/settings/settings-environment-filter";
Expand Down Expand Up @@ -297,6 +298,11 @@ const SETTINGS_SCREENS = {
linking: "settings/notifications",
options: settingsPage(),
}),
SettingsConnectService: createNativeStackScreen({
screen: SettingsConnectServiceRouteScreen,
linking: "settings/connect-service",
options: settingsPage(),
}),
SettingsThreads: createNativeStackScreen({
screen: SettingsThreadsRouteScreen,
linking: "settings/thread-preferences",
Expand Down
1 change: 1 addition & 0 deletions apps/mobile/src/features/cloud/CloudAuthProvider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ vi.mock("../../state/use-composer-drafts", () => ({
vi.mock("./publicConfig", () => ({
resolveCloudPublicConfig: vi.fn(() => ({
clerk: { publishableKey: null },
oidc: { issuer: null, clientId: null },
relay: { url: null },
})),
resolveRelayClerkTokenOptions: vi.fn(),
Expand Down
73 changes: 65 additions & 8 deletions apps/mobile/src/features/cloud/CloudAuthProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,34 @@
import { ClerkProvider, getClerkInstance } from "@clerk/expo";
import { ClerkProvider, getClerkInstance, useAuth, useUser } from "@clerk/expo";
import { tokenCache } from "@clerk/expo/token-cache";
import type { ReactNode } from "react";
import type { OidcController } from "@t3tools/client-runtime/relay";
import { type ReactNode, useSyncExternalStore } from "react";

import { cloudAccountService, deactivateCloudRelayAccount } from "./cloudAccountService";
import { resolveCloudPublicConfig } from "./publicConfig";
import {
cloudAccountService,
createCloudRelayAccountService,
deactivateCloudRelayAccount,
} from "./cloudAccountService";
import { CloudAuthContext, type CloudAuth } from "./cloudAuth";
import { getMobileOidcController } from "./oidc/mobileOidc";
import {
cloudAuthProvider,
resolveCloudPublicConfig,
resolveRelayClerkTokenOptions,
} from "./publicConfig";

const cloudConfig = resolveCloudPublicConfig();
// Build-time constant: null when this build has no cloud config.
const publishableKey = cloudConfig.relay.url ? cloudConfig.clerk.publishableKey : null;
const provider = cloudAuthProvider(cloudConfig);
const oidcController = provider === "oidc" ? getMobileOidcController() : null;
// Build-time constant: null when this build has no Clerk config, or uses an OIDC provider instead.
const publishableKey =
provider !== "oidc" && cloudConfig.relay.url ? cloudConfig.clerk.publishableKey : null;

if (publishableKey) {
if (oidcController) {
// The ID token is what the relay verifies, so that is the token the account service hands out.
createCloudRelayAccountService<OidcController>((source) => source.getToken).attach(
oidcController,
);
} else if (publishableKey) {
// The same native singleton ClerkProvider renders with, so the service
// observes it for the app's lifetime without a React subscription.
cloudAccountService.attach(getClerkInstance({ publishableKey }));
Expand All @@ -19,14 +38,52 @@ if (publishableKey) {
deactivateCloudRelayAccount();
}

function OidcAuthBridge(props: {
readonly controller: OidcController;
readonly children: ReactNode;
}) {
const snapshot = useSyncExternalStore(props.controller.subscribe, props.controller.getSnapshot);
const value: CloudAuth = {
provider: "oidc",
isLoaded: true,
isSignedIn: snapshot.userId !== null,
userId: snapshot.userId,
accountLabel: snapshot.label,
getToken: props.controller.getToken,
signOut: props.controller.signOut,
};
return <CloudAuthContext.Provider value={value}>{props.children}</CloudAuthContext.Provider>;
}

function ClerkAuthBridge(props: { readonly children: ReactNode }) {
// A session with steps pending must not look signed out, or activation would look like a new sign-in.
const { isLoaded, isSignedIn, userId, getToken, signOut } = useAuth({
treatPendingAsSignedOut: false,
});
const { user } = useUser();
const value: CloudAuth = {
provider: "clerk",
isLoaded,
isSignedIn: isSignedIn === true,
userId: userId ?? null,
accountLabel: user?.primaryEmailAddress?.emailAddress ?? null,
getToken: () => getToken(resolveRelayClerkTokenOptions()),
signOut: () => signOut(),
};
return <CloudAuthContext.Provider value={value}>{props.children}</CloudAuthContext.Provider>;
}

export function CloudAuthProvider(props: { readonly children: ReactNode }) {
if (oidcController) {
return <OidcAuthBridge controller={oidcController}>{props.children}</OidcAuthBridge>;
}
if (!publishableKey) {
return props.children;
}

return (
<ClerkProvider publishableKey={publishableKey} tokenCache={tokenCache}>
{props.children}
<ClerkAuthBridge>{props.children}</ClerkAuthBridge>
</ClerkProvider>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { AppBar } from "../../components/ui/AppBar";
import { Button } from "../../components/ui/Button";
import { ScreenScrollView as ScrollView } from "../../components/ui/ScreenScrollView";

import { useAuth } from "@clerk/expo";
import { useNavigation } from "@react-navigation/native";
import { useState } from "react";
import { View } from "react-native";
Expand All @@ -17,6 +16,7 @@ import { CloudEnvironmentRows } from "../connection/CloudEnvironmentRows";
import { splitEnvironmentSections } from "../connection/environmentSections";
import { useConnectionController } from "../connection/useConnectionController";
import { optOutOfConnectOnboarding } from "./connectOnboardingOptOut";
import { useCloudAuth } from "./cloudAuth";
import { hasCloudPublicConfig } from "./publicConfig";

// Only reachable with cloud config: onboarding is requested after a T3 Connect
Expand All @@ -29,7 +29,7 @@ function ConfiguredConnectOnboardingRouteScreen() {
const gt = useGT();
const navigation = useNavigation();
const insets = useSafeAreaInsets();
const { isSignedIn, userId } = useAuth({ treatPendingAsSignedOut: false });
const { isSignedIn, userId } = useCloudAuth();
const { connectedEnvironments, onSetEnvironmentEnabled, onRemoveEnvironmentPress } =
useRemoteConnections();
const { refreshRelayEnvironments } = useConnectionController();
Expand Down
4 changes: 3 additions & 1 deletion apps/mobile/src/features/cloud/T3ConnectProfilePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ function endpointLabel(
): string {
return environment.endpoint.providerKind === "cloudflare_tunnel"
? resolve(msg("Managed tunnel"))
: resolve(msg("Activity publishing only"));
: environment.endpoint.providerKind === "t3_relay"
? resolve(msg("Carried by the relay"))
: resolve(msg("Activity publishing only"));
}

function confirmDeregister(environment: RelayClientEnvironmentRecord, onConfirm: () => void) {
Expand Down
68 changes: 38 additions & 30 deletions apps/mobile/src/features/cloud/cloudAccountService.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { getClerkInstance } from "@clerk/expo";
import {
type CloudAccountSource,
createCloudAccountService,
ManagedRelay,
setManagedRelaySession,
Expand Down Expand Up @@ -50,8 +51,9 @@ function clerkTokenReader(clerk: ClerkInstance): () => Promise<string | null> {
clerk.session ? await clerk.session.getToken(resolveRelayClerkTokenOptions()) : null;
}

const cleanUpCloudAccount = async (
clerk: ClerkInstance,
const cleanUpCloudAccount = async <S>(
readToken: (source: S) => () => Promise<string | null>,
source: S,
accountId: string | null,
wasActive: boolean,
) => {
Expand All @@ -69,9 +71,7 @@ const cleanUpCloudAccount = async (
...(wasActive
? [
settleAsyncResult(() =>
runtime.runPromiseExit(
unregisterAgentAwarenessDeviceForCurrentUser(clerkTokenReader(clerk)),
),
runtime.runPromiseExit(unregisterAgentAwarenessDeviceForCurrentUser(readToken(source))),
),
]
: []),
Expand All @@ -81,28 +81,36 @@ const cleanUpCloudAccount = async (
}
};

export const cloudAccountService = createCloudAccountService<ClerkInstance>({
deactivate: deactivateCloudRelayAccount,
// Detaching is not a sign-out: the user is usually still signed in, so keep
// lock-screen activities and the persisted registration for the next attach.
detach: () => {
releaseAgentAwarenessRelayTokenProvider();
setManagedRelaySession(appAtomRegistry, null);
},
// A not-yet-presented onboarding request belongs to the account that left.
onSignOutTransition: clearConnectOnboardingRequest,
cleanUp: ({ source, accountId, wasActive }) => cleanUpCloudAccount(source, accountId, wasActive),
prepare: async ({ source, accountId, isCurrent }) => {
const storedAccount = await getComposerCloudAccountId();
if (storedAccount !== null && storedAccount !== accountId) {
await cleanUpCloudAccount(source, storedAccount, false);
}
if (!isCurrent()) return;
await restoreCloudComposerDrafts(accountId);
},
activate: ({ source, accountId, isAccountTransition }) => {
activateCloudRelayAccount(accountId, clerkTokenReader(source));
// Issued after cleanup so the sheet never lists the previous account's environments.
if (isAccountTransition) requestConnectOnboarding(accountId);
},
});
/** Shared by every sign-in provider: only how a source yields its relay token differs. */
export function createCloudRelayAccountService<S extends CloudAccountSource>(
readToken: (source: S) => () => Promise<string | null>,
) {
return createCloudAccountService<S>({
deactivate: deactivateCloudRelayAccount,
// Detaching is not a sign-out: the user is usually still signed in, so keep
// lock-screen activities and the persisted registration for the next attach.
detach: () => {
releaseAgentAwarenessRelayTokenProvider();
setManagedRelaySession(appAtomRegistry, null);
},
// A not-yet-presented onboarding request belongs to the account that left.
onSignOutTransition: clearConnectOnboardingRequest,
cleanUp: ({ source, accountId, wasActive }) =>
cleanUpCloudAccount(readToken, source, accountId, wasActive),
prepare: async ({ source, accountId, isCurrent }) => {
const storedAccount = await getComposerCloudAccountId();
if (storedAccount !== null && storedAccount !== accountId) {
await cleanUpCloudAccount(readToken, source, storedAccount, false);
}
if (!isCurrent()) return;
await restoreCloudComposerDrafts(accountId);
},
activate: ({ source, accountId, isAccountTransition }) => {
activateCloudRelayAccount(accountId, readToken(source));
// Issued after cleanup so the sheet never lists the previous account's environments.
if (isAccountTransition) requestConnectOnboarding(accountId);
},
});
}

export const cloudAccountService = createCloudRelayAccountService<ClerkInstance>(clerkTokenReader);
13 changes: 13 additions & 0 deletions apps/mobile/src/features/cloud/cloudAuth.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { SIGNED_OUT_CLOUD_AUTH, type CloudAuthState } from "@t3tools/client-runtime/relay";
import { createContext, useContext } from "react";

/** Screens read this instead of a provider's own hooks. */
export interface CloudAuth extends CloudAuthState {
readonly signOut: () => Promise<void>;
}

const SIGNED_OUT: CloudAuth = { ...SIGNED_OUT_CLOUD_AUTH, signOut: async () => {} };

export const CloudAuthContext = createContext<CloudAuth>(SIGNED_OUT);

export const useCloudAuth = (): CloudAuth => useContext(CloudAuthContext);
5 changes: 4 additions & 1 deletion apps/mobile/src/features/cloud/linkEnvironment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,10 @@ function ensureLinkedEnvironmentMatches(input: {
message: m(msg("Relay returned credentials for a different environment.")),
});
}
if (input.link.endpoint.providerKind !== input.expectedProviderKind) {
const { providerKind } = input.link.endpoint;
// A self-hosted relay may carry a publish-only environment over its own channel.
const carriedByRelay = input.expectedProviderKind === "manual" && providerKind === "t3_relay";
if (providerKind !== input.expectedProviderKind && !carriedByRelay) {
return new CloudEnvironmentLinkError({
message: m(msg("Relay returned credentials for a different endpoint provider.")),
});
Expand Down
Loading
Loading