wip: Custom mirroring tangled knot written in Rust
rust tangled mirror knot
1

Configure Feed

Select the types of activity you want to include in your feed.

oauth: improve metadata generation

Clément (Jun 9, 2026, 8:30 PM +0200) 1567febc 6d0f3118

+42 -36
-1
app/package.json
··· 2 2 "name": "app", 3 3 "type": "module", 4 4 "scripts": { 5 - "postinstall": "node ./scripts/generate-metadata.ts", 6 5 "start": "vite", 7 6 "dev": "vite", 8 7 "build": "vite build",
+22 -2
app/vite.config.ts
··· 1 1 import tailwindcss from "@tailwindcss/vite"; 2 - import { defineConfig } from "vite"; 2 + import { mkdirSync, writeFileSync } from "node:fs"; 3 + import { defineConfig, type Plugin } from "vite"; 3 4 import solidPlugin from "vite-plugin-solid"; 4 5 import devtools from "solid-devtools/vite"; 6 + import { buildOAuthClientMetadata } from "./src/oauth_metadata.ts"; 7 + 8 + function oauthMetadataPlugin(): Plugin { 9 + return { 10 + name: "oauth-metadata", 11 + configResolved(config) { 12 + const metadata = buildOAuthClientMetadata( 13 + config.env.VITE_HOSTNAME || "http://127.0.0.1:5173", 14 + config.command === "serve", 15 + ); 16 + 17 + mkdirSync("public", { recursive: true }); 18 + writeFileSync( 19 + "public/oauth-client-metadata.json", 20 + JSON.stringify(metadata), 21 + ); 22 + }, 23 + }; 24 + } 5 25 6 26 export default defineConfig({ 7 - plugins: [devtools(), solidPlugin(), tailwindcss()], 27 + plugins: [devtools(), solidPlugin(), tailwindcss(), oauthMetadataPlugin()], 8 28 server: { 9 29 // for OAuth, "localhost" hostname is not allowed (RFC 8252) 10 30 host: "127.0.0.1",
-17
app/scripts/generate-metadata.ts
··· 1 - import { existsSync, mkdirSync, writeFileSync } from "node:fs"; 2 - import { dirname } from "node:path"; 3 - import { fileURLToPath } from "node:url"; 4 - import { OAUTH_CLIENT_METADATA } from "../src/oauth_metadata.ts"; 5 - 6 - const __filename = fileURLToPath(import.meta.url); 7 - const __dirname = dirname(__filename); 8 - const public_dir = `${__dirname}/../public`; 9 - 10 - if (!existsSync(public_dir)) { 11 - mkdirSync(public_dir); 12 - } 13 - 14 - writeFileSync( 15 - `${public_dir}/oauth-client-metadata.json`, 16 - JSON.stringify(OAUTH_CLIENT_METADATA), 17 - );
+20 -16
app/src/oauth_metadata.ts
··· 1 - const baseUrl = import.meta.env?.VITE_BASE_URL || "http://127.0.0.1:5173"; 2 - 3 1 export const OAUTH_SCOPE = "atproto repo:sh.tangled.repo"; 4 - const redirect_uri = baseUrl; 5 - const client_id = import.meta.env?.DEV 6 - ? `http://localhost?redirect_uri=${encodeURIComponent(redirect_uri)}&scope=${encodeURIComponent(OAUTH_SCOPE)}` 7 - : `${baseUrl}/oauth-client-metadata.json`; 8 2 9 - export const OAUTH_CLIENT_METADATA = { 10 - client_id, 11 - client_uri: baseUrl, 12 - redirect_uris: [redirect_uri], 13 - scope: OAUTH_SCOPE, 14 - application_type: "web", 15 - token_endpoint_auth_method: "none", 16 - grant_types: ["authorization_code"], 17 - dpop_bound_access_tokens: true, 18 - }; 3 + export function buildOAuthClientMetadata(baseUrl: URL, isDev: boolean) { 4 + const client_id = isDev 5 + ? `http://localhost?redirect_uri=${encodeURIComponent(baseUrl.toString())}&scope=${encodeURIComponent(OAUTH_SCOPE)}` 6 + : `${baseUrl.toString()}/oauth-client-metadata.json`; 7 + return { 8 + client_id, 9 + client_uri: baseUrl.toString(), 10 + redirect_uris: [baseUrl.toString()], 11 + scope: OAUTH_SCOPE, 12 + application_type: "web", 13 + token_endpoint_auth_method: "none", 14 + grant_types: ["authorization_code"], 15 + dpop_bound_access_tokens: true, 16 + }; 17 + } 18 + 19 + export const OAUTH_CLIENT_METADATA = buildOAuthClientMetadata( 20 + import.meta.env?.VITE_HOSTNAME ?? "http://127.0.0.1:5173", 21 + import.meta.env?.DEV ?? false, 22 + );