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

@ -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).
- 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("+");
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 };
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<string> => {
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<string, any> = clients
export default {
callbackUrl,
discord, github,
createAuthUrl,
extractCode,
getAuthClient,
...clients
}

View File

@ -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, []),
}

View File

@ -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;
</script>
<div class="flex flex-col-reverse md:flex-row gap-2 md:gap-4">
@ -32,7 +32,7 @@
</div>
<div class="entry flex flex-wrap gap-1.5 p-1">
<p class="text-xl ms-2">auth via:</p>
{#each ['discord', 'github'] as platform}
{#each ['indielogin', 'discord', 'github'] as platform}
<input
type="submit"
value={platform}