feat: add indielogin login

This commit is contained in:
dusk 2024-09-24 00:49:25 +03:00
parent 915d7877d2
commit bdf586ca2f
Signed by: dusk
SSH Key Fingerprint: SHA256:Abmvag+juovVufZTxyWY8KcVgrznxvBjQpJesv071Aw
4 changed files with 36 additions and 16 deletions

View File

@ -3,3 +3,7 @@ code for my personal website.
- the website itself uses sveltekit (w/ typescript) and tailwindcss. it's served with bun. - 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. - 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). - 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

View File

@ -22,7 +22,7 @@ class OauthConfig {
joinScopes: (scopes: string[]) => string = (scopes) => scopes.join("+"); joinScopes: (scopes: string[]) => string = (scopes) => scopes.join("+");
getAuthParams: (params: Record<string, string>, config: OauthConfig) => Record<string, string> = (params) => { return params }; getAuthParams: (params: Record<string, string>, config: OauthConfig) => Record<string, string> = (params) => { return params };
getTokenParams: (params: Record<string, string>, config: OauthConfig) => Record<string, string> = (params) => { return params }; getTokenParams: (params: Record<string, string>, config: OauthConfig) => Record<string, string> = (params) => { return params };
extractTokenResponse: (tokenResp: any) => TokenResponse = (tokenResp) => { extractTokenResponse: (tokenResp: any) => any = (tokenResp) => {
return { return {
accessToken: tokenResp.access_token, accessToken: tokenResp.access_token,
tokenType: tokenResp.token_type, 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<string> => {
let me: string = tokenResp.me
me = me.replace('https://', '').replace('http://', '')
return me
}
}
export const generateState = () => { export const generateState = () => {
const randomValues = new Uint8Array(32) const randomValues = new Uint8Array(32)
crypto.getRandomValues(randomValues) crypto.getRandomValues(randomValues)
@ -185,22 +204,18 @@ export const extractCode = (url: URL, cookies: Cookies) => {
} }
export const getAuthClient = (name: string) => { export const getAuthClient = (name: string) => {
switch (name) { return clientsMap[name]
case "discord":
return discord
case "github":
return github
default:
return null
} }
const clients = {
discord, github, indielogin
} }
const clientsMap: Record<string, any> = clients
export default { export default {
callbackUrl, callbackUrl,
discord, github,
createAuthUrl, createAuthUrl,
extractCode, extractCode,
getAuthClient, getAuthClient,
...clients
} }

View File

@ -44,6 +44,7 @@ const postAction = (client: any, scopes: string[]) => {
} }
export const actions = { export const actions = {
post_indielogin: postAction(auth.indielogin, []),
post_discord: postAction(auth.discord, ["identify"]), post_discord: postAction(auth.discord, ["identify"]),
post_github: postAction(auth.github, []), post_github: postAction(auth.github, []),
} }

View File

@ -2,8 +2,8 @@
import Window from '../../components/window.svelte'; import Window from '../../components/window.svelte';
export let data; export let data;
const hasPreviousPage = data.page > 1; $: hasPreviousPage = data.page > 1;
const hasNextPage = data.hasNext; $: hasNextPage = data.hasNext;
</script> </script>
<div class="flex flex-col-reverse md:flex-row gap-2 md:gap-4"> <div class="flex flex-col-reverse md:flex-row gap-2 md:gap-4">
@ -32,7 +32,7 @@
</div> </div>
<div class="entry flex flex-wrap gap-1.5 p-1"> <div class="entry flex flex-wrap gap-1.5 p-1">
<p class="text-xl ms-2">auth via:</p> <p class="text-xl ms-2">auth via:</p>
{#each ['discord', 'github'] as platform} {#each ['indielogin', 'discord', 'github'] as platform}
<input <input
type="submit" type="submit"
value={platform} value={platform}