Statusphere running on a slice 馃崟
at main 62 lines 2.0 kB view raw
1import { OAuthClient, DenoKVOAuthStorage } from "@slices/oauth"; 2import { SessionStore, DenoKVAdapter, withOAuthSession } from "@slices/session"; 3import { AtProtoClient } from "./generated_client.ts"; 4 5// Environment configuration 6export const PORT = parseInt(Deno.env.get("PORT") || "8080"); 7export const DATABASE_URL = Deno.env.get("DATABASE_URL") || "./statusphere.db"; 8export const OAUTH_CLIENT_ID = Deno.env.get("OAUTH_CLIENT_ID") || ""; 9export const OAUTH_CLIENT_SECRET = Deno.env.get("OAUTH_CLIENT_SECRET") || ""; 10export const OAUTH_REDIRECT_URI = 11 Deno.env.get("OAUTH_REDIRECT_URI") || 12 `http://localhost:${PORT}/oauth/callback`; 13export const OAUTH_AIP_BASE_URL = 14 Deno.env.get("OAUTH_AIP_BASE_URL") || "https://bsky.social"; 15export const SLICE_URI = 16 Deno.env.get("SLICE_URI") || 17 "at://did:plc:bcgltzqazw5tb6k2g3ttenbj/social.slices.slice/3lx5y476bws2q"; 18export const SLICES_API_URL = Deno.env.get("SLICES_API_URL") || ""; 19 20// OAuth and Session setup 21// In Deno Deploy, don't specify a path to use the default KV store 22const kv = await Deno.openKv( 23 Deno.env.get("ENV") === "production" ? undefined : DATABASE_URL 24); 25const oauthStorage = new DenoKVOAuthStorage(kv); 26export const oauthClient = new OAuthClient( 27 { 28 clientId: OAUTH_CLIENT_ID, 29 clientSecret: OAUTH_CLIENT_SECRET, 30 authBaseUrl: OAUTH_AIP_BASE_URL, 31 redirectUri: OAUTH_REDIRECT_URI, 32 scopes: [ 33 "openid", 34 "profile", 35 "email", 36 "atproto:atproto", 37 "atproto:transition:generic", 38 ], 39 }, 40 oauthStorage 41); 42 43export const sessionStore = new SessionStore({ 44 adapter: new DenoKVAdapter(kv), 45 cookieOptions: { 46 httpOnly: true, 47 secure: Deno.env.get("ENV") === "production", 48 sameSite: "lax", 49 path: "/", 50 }, 51}); 52 53export const oauthSessions = withOAuthSession(sessionStore, oauthClient, { 54 autoRefresh: true, 55}); 56 57// Slices AT Protocol client 58export const atprotoClient = new AtProtoClient( 59 SLICES_API_URL, 60 SLICE_URI, 61 oauthClient 62);