Skip to content

Commit ac07dd1

Browse files
committed
Issue access tokens for Syntax Lab's MCP endpoint
Add https://lab.syntax.fm/mcp to the OAuth provider's validAudiences, beside Syntax Auth's own API (Better Auth's default), so members' agents can sign in to Lab's MCP endpoint (Lab dex task egyueuny; authorized by Scott 2026-10-02). Proof: pnpm test (95 pass, incl. oauth_audiences.test.ts), pnpm check, pnpm lint.
1 parent 7305633 commit ac07dd1

3 files changed

Lines changed: 25 additions & 0 deletions

File tree

‎src/lib/server/auth.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { SYNTAX_TEST_TRUSTED_ORIGINS } from '../utils/local_hosts';
88
import * as schema from './db/schema';
99
import type { AuthEnvironment } from './env';
1010
import { LOCAL_DEVELOPER } from './local_developer';
11+
import { get_oauth_valid_audiences } from './oauth_audiences';
1112

1213
export function create_auth(env: AuthEnvironment) {
1314
const database = drizzle(env.DB, { schema });
@@ -80,6 +81,8 @@ export function create_auth(env: AuthEnvironment) {
8081
scopes: ['openid', 'profile', 'email', 'offline_access'],
8182
allowDynamicClientRegistration: false,
8283
allowUnauthenticatedClientRegistration: false,
84+
// Without this, Better Auth accepts only its own base URL as a token `resource`.
85+
validAudiences: get_oauth_valid_audiences(better_auth_origin),
8386
silenceWarnings: {
8487
oauthAuthServerConfig: true
8588
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import assert from 'node:assert/strict';
2+
import { test } from 'node:test';
3+
4+
import { get_oauth_valid_audiences } from './oauth_audiences';
5+
6+
test("tokens can be issued for Syntax Auth's own API, as before, and for Syntax Lab's MCP endpoint only", () => {
7+
assert.deepEqual(get_oauth_valid_audiences('https://auth.syntax.fm'), [
8+
'https://auth.syntax.fm/api/auth',
9+
'https://lab.syntax.fm/mcp'
10+
]);
11+
});

‎src/lib/server/oauth_audiences.ts‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// The audiences Syntax Auth issues OAuth access tokens for (RFC 8707 `resource`). The token
2+
// endpoint refuses any other `resource`, so a token is only ever usable where it was meant to go.
3+
// - Syntax Auth's own API, which is Better Auth's default (its base URL plus `/api/auth`).
4+
// - Syntax Lab's MCP endpoint: members' own agents (Claude Code, pi) sign in here and send the
5+
// token to Lab, which verifies it against this service's published keys
6+
// (syntax-lab docs/tech/agent-access.md, "Built: the MCP endpoint").
7+
export const SYNTAX_LAB_MCP_AUDIENCE = 'https://lab.syntax.fm/mcp';
8+
9+
export function get_oauth_valid_audiences(better_auth_origin: string): string[] {
10+
return [`${better_auth_origin}/api/auth`, SYNTAX_LAB_MCP_AUDIENCE];
11+
}

0 commit comments

Comments
 (0)