data endpoint for entity 90008 (aka. a website)
0
fork

Configure Feed

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

feat: dont use arctic i hate libraries i hate libraries

+25 -5
bun.lockb

This is a binary file and will not be displayed.

+1 -1
package.json
··· 39 39 "type": "module", 40 40 "dependencies": { 41 41 "@std/toml": "npm:@jsr/std__toml", 42 - "arctic": "^2.0.0-next.5", 42 + "base64url": "^3.0.1", 43 43 "rehype-autolink-headings": "^7.1.0", 44 44 "rehype-slug": "^6.0.0" 45 45 },
+23 -3
src/lib/guestbookAuth.ts
··· 2 2 import { env } from "$env/dynamic/private"; 3 3 import { PUBLIC_BASE_URL } from "$env/static/public"; 4 4 import type { Cookies } from "@sveltejs/kit"; 5 - import { Discord, generateState, GitHub } from "arctic"; 5 + import base64url from "base64url"; 6 6 7 7 export const callbackUrl = `${PUBLIC_BASE_URL}/guestbook/` 8 8 9 - export const discord = new Discord(env.DISCORD_CLIENT_ID, "", callbackUrl) 10 - export const github = new GitHub(env.GITHUB_CLIENT_ID, "", callbackUrl) 9 + export const discord = { 10 + getAuthUrl: (state: string, scopes: string[] = []) => { 11 + const client_id = env.DISCORD_CLIENT_ID 12 + const redir_uri = encodeURIComponent(callbackUrl) 13 + const scope = scopes.join("+") 14 + return `https://discord.com/oauth2/authorize?client_id=${client_id}&response_type=code&redirect_uri=${redir_uri}&scope=${scope}&state=${state}` 15 + } 16 + } 17 + export const github = { 18 + getAuthUrl: (state: string, scopes: string[] = []) => { 19 + const client_id = env.GITHUB_CLIENT_ID 20 + const redir_uri = encodeURIComponent(callbackUrl) 21 + const scope = encodeURIComponent(scopes.join(" ")) 22 + return `https://github.com/login/oauth/authorize?client_id=${client_id}&redirect_uri=${redir_uri}&scope=${scope}&state=${state}` 23 + } 24 + } 25 + 26 + export const generateState = () => { 27 + const randomValues = new Uint8Array(32) 28 + crypto.getRandomValues(randomValues) 29 + return base64url(Buffer.from(randomValues)) 30 + } 11 31 12 32 export const createAuthUrl = (authCb: (state: string) => URL, cookies: Cookies) => { 13 33 const state = generateState()
+1 -1
src/routes/guestbook/+page.server.ts
··· 40 40 const params = new URLSearchParams({ author, content }) 41 41 scopedCookies.set("postData", params.toString()) 42 42 // get auth url to redirect user to 43 - const authUrl = await auth.createAuthUrl((state) => client.createAuthorizationURL(state, scopes), cookies) 43 + const authUrl = auth.createAuthUrl(client.getAuthUrl, cookies) 44 44 redirect(303, authUrl) 45 45 } 46 46 }