From bdf586ca2fded4399fd8260a7fd0967999049fcd Mon Sep 17 00:00:00 2001 From: dusk Date: Tue, 24 Sep 2024 00:49:25 +0300 Subject: [PATCH] feat: add indielogin login --- README.md | 6 ++++- src/lib/guestbookAuth.ts | 39 +++++++++++++++++++--------- src/routes/guestbook/+page.server.ts | 1 + src/routes/guestbook/+page.svelte | 6 ++--- 4 files changed, 36 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 033ba35..290478d 100644 --- a/README.md +++ b/README.md @@ -2,4 +2,8 @@ code for my personal website. - the website itself uses sveltekit (w/ typescript) and tailwindcss. it's served with bun. - the guestbook backend is written in scala, with http4s. it's compiled to a native binary using graalvm. -- it's deployed to my server with nix, so it's packaged with nix (see flake.nix). \ No newline at end of file +- it's deployed to my server with nix, so it's packaged with nix (see flake.nix). + +notes to self: + +- don't use tags starting with h- in root layout or page, this causes hcard parsers to trip up \ No newline at end of file diff --git a/src/lib/guestbookAuth.ts b/src/lib/guestbookAuth.ts index 042952d..f414c02 100644 --- a/src/lib/guestbookAuth.ts +++ b/src/lib/guestbookAuth.ts @@ -22,7 +22,7 @@ class OauthConfig { joinScopes: (scopes: string[]) => string = (scopes) => scopes.join("+"); getAuthParams: (params: Record, config: OauthConfig) => Record = (params) => { return params }; getTokenParams: (params: Record, config: OauthConfig) => Record = (params) => { return params }; - extractTokenResponse: (tokenResp: any) => TokenResponse = (tokenResp) => { + extractTokenResponse: (tokenResp: any) => any = (tokenResp) => { return { accessToken: tokenResp.access_token, tokenType: tokenResp.token_type, @@ -150,6 +150,25 @@ export const github = { } } +export const indielogin = { + name: 'indielogin', + ...genericOauthClient( + new OauthConfig( + PUBLIC_BASE_URL, + '', + 'https://indielogin.com/auth', + 'https://indielogin.com/auth', + ) + .withTokenRequestHeaders({ 'Accept': 'application/json' }) + .withExtractTokenResponse((rawResp) => {return {me: rawResp.me}}) + ), + identifyToken: async (tokenResp: any): Promise => { + let me: string = tokenResp.me + me = me.replace('https://', '').replace('http://', '') + return me + } +} + export const generateState = () => { const randomValues = new Uint8Array(32) crypto.getRandomValues(randomValues) @@ -185,22 +204,18 @@ export const extractCode = (url: URL, cookies: Cookies) => { } export const getAuthClient = (name: string) => { - switch (name) { - case "discord": - return discord - - case "github": - return github - - default: - return null - } + return clientsMap[name] } +const clients = { + discord, github, indielogin +} +const clientsMap: Record = clients + export default { callbackUrl, - discord, github, createAuthUrl, extractCode, getAuthClient, + ...clients } \ No newline at end of file diff --git a/src/routes/guestbook/+page.server.ts b/src/routes/guestbook/+page.server.ts index 29d65d7..5a7ae91 100644 --- a/src/routes/guestbook/+page.server.ts +++ b/src/routes/guestbook/+page.server.ts @@ -44,6 +44,7 @@ const postAction = (client: any, scopes: string[]) => { } export const actions = { + post_indielogin: postAction(auth.indielogin, []), post_discord: postAction(auth.discord, ["identify"]), post_github: postAction(auth.github, []), } diff --git a/src/routes/guestbook/+page.svelte b/src/routes/guestbook/+page.svelte index d24660f..05c24aa 100644 --- a/src/routes/guestbook/+page.svelte +++ b/src/routes/guestbook/+page.svelte @@ -2,8 +2,8 @@ import Window from '../../components/window.svelte'; export let data; - const hasPreviousPage = data.page > 1; - const hasNextPage = data.hasNext; + $: hasPreviousPage = data.page > 1; + $: hasNextPage = data.hasNext;
@@ -32,7 +32,7 @@

auth via:

- {#each ['discord', 'github'] as platform} + {#each ['indielogin', 'discord', 'github'] as platform}