diff --git a/app.config.ts b/app.config.ts index cac6d26..0d91e94 100644 --- a/app.config.ts +++ b/app.config.ts @@ -4,29 +4,14 @@ import devtools from 'solid-devtools/vite'; export default defineConfig({ vite: { - resolve: { - alias: [ - { find: '@', replacement: 'F:\\Github\\calque\\node_modules\\' }, - ], - }, html: { cspNonce: 'KAAS_IS_AWESOME', }, - // css: { - // postcss: { - // }, - // }, plugins: [ devtools({ autoname: true, }), solidSvg(), - { - name: 'temp', - configResolved(config) { - console.log(config.resolve.alias); - }, - } ], }, solid: { diff --git a/public/.well-known/web-identity b/public/.well-known/web-identity index 0126daa..92ad901 100644 --- a/public/.well-known/web-identity +++ b/public/.well-known/web-identity @@ -1,5 +1,5 @@ { "provider_urls": [ - "http://localhost:3000/fedcm.json" + "http://localhost:3000/auth/idp/api/config" ] } diff --git a/src/features/auth/index.ts b/src/features/auth/index.ts index 6c6d4e3..09bf607 100644 --- a/src/features/auth/index.ts +++ b/src/features/auth/index.ts @@ -14,10 +14,10 @@ export interface User { } const USERS: User[] = [ - { id: '20d701f3-0f9f-4c21-a379-81b49f755f9e', username: 'chris', credential: 'test', givenName: 'Chris', familyName: 'Kruining', picture: '', approvedClients: [] }, - { id: '10199201-1564-47db-b67b-07088ff05de8', username: 'john', credential: 'test', givenName: 'John', familyName: 'Doe', picture: '', approvedClients: [] }, - { id: '633c44b3-8d3d-4dd1-8e1c-7de355d6dced', username: 'chris_alt', credential: 'test', givenName: 'Chris', familyName: 'Kruining', picture: '', approvedClients: [] }, - { id: 'b9759798-8a41-4961-94a6-feb2372de9cf', username: 'john_alt', credential: 'test', givenName: 'John', familyName: 'Doe', picture: '', approvedClients: [] }, + { id: '20d701f3-0f9f-4c21-a379-81b49f755f9e', username: 'chris', credential: 'test', givenName: 'Chris', familyName: 'Kruining', picture: '', approvedClients: [ '/auth/client' ] }, + { id: '10199201-1564-47db-b67b-07088ff05de8', username: 'john', credential: 'test', givenName: 'John', familyName: 'Doe', picture: '', approvedClients: [ '/auth/client' ] }, + { id: '633c44b3-8d3d-4dd1-8e1c-7de355d6dced', username: 'chris_alt', credential: 'test', givenName: 'Chris', familyName: 'Kruining', picture: '', approvedClients: [ '/auth/client' ] }, + { id: 'b9759798-8a41-4961-94a6-feb2372de9cf', username: 'john_alt', credential: 'test', givenName: 'John', familyName: 'Doe', picture: '', approvedClients: [ '/auth/client' ] }, ]; export const getUser = (idOrUsername: string) => { @@ -41,9 +41,13 @@ export const signOut = async () => { }; export const use = (...middlewares: Middleware[]) => { - return (event: APIEvent) => { + return async (event: APIEvent) => { + console.log(`received ${event.request.url}`); + for (const handler of middlewares) { - const response = handler(event); + const response = await handler(event); + + console.log(response?.status); if (response !== undefined) { return response; @@ -76,6 +80,8 @@ export const assertApiSession = async ({ request, locals }: APIEvent) => { const user = await getSession(); if (user === undefined) { + console.log('user session not available'); + return json({ error: 'not signed in' }, { status: 401 }); } diff --git a/src/routes/auth/client/index.tsx b/src/routes/auth/client/index.tsx index aafdf75..e9bb3da 100644 --- a/src/routes/auth/client/index.tsx +++ b/src/routes/auth/client/index.tsx @@ -2,26 +2,30 @@ import { onMount } from "solid-js"; export default function Index() { onMount(async () => { - try { - // navigator.login.setStatus('logged-in'); + const user = await fetch('/auth/idp/api/user-info').then(r => r.json()); - const credential = await navigator.credentials.get({ - identity: { - providers: [{ - configURL: new URL('http://localhost:3000/fedcm.json'), - clientId: '/auth/client', - nonce: 'kaas', - loginHint: 'chris', - }], - mode: 'passive', - context: undefined, - }, - mediation: undefined, - }); + console.log(user); - console.log(credential); - } catch(e) { - console.error(e); + if (user === undefined || true) { + try { + const credential = await navigator.credentials.get({ + identity: { + providers: [{ + configURL: new URL('http://localhost:3000/auth/idp/api/config'), + clientId: '/auth/client', + nonce: 'kaas', + loginHint: 'chris', + }], + mode: 'passive', + context: undefined, + }, + mediation: 'silent', + }); + + console.log(credential); + } catch(e) { + console.error(e); + } } }); diff --git a/src/routes/auth/idp/api/[...404].ts b/src/routes/auth/idp/api/[...404].ts index 72eefc3..e18a242 100644 --- a/src/routes/auth/idp/api/[...404].ts +++ b/src/routes/auth/idp/api/[...404].ts @@ -4,5 +4,5 @@ import { APIEvent } from "@solidjs/start/server"; export const GET = ({ request }: APIEvent) => { console.error(`url not found ${request.url}`); - // return json({ error: `url ${request.url} is not implemented` }, { status: 404 }) + return json({ error: `url ${request.url} is not implemented` }, { status: 404 }) }; \ No newline at end of file diff --git a/src/routes/auth/idp/api/accounts.ts b/src/routes/auth/idp/api/accounts.ts index e660048..85a1946 100644 --- a/src/routes/auth/idp/api/accounts.ts +++ b/src/routes/auth/idp/api/accounts.ts @@ -2,8 +2,8 @@ import { json } from "@solidjs/router"; import { APIEvent } from "@solidjs/start/server"; import { assertApiSession, assertCsrf, use, User } from "~/features/auth"; -export const GET = use(assertCsrf, assertApiSession, async (event: APIEvent) => { - const user = event.locals.user as User; +export const GET = use(assertCsrf, assertApiSession, async ({ locals }: APIEvent) => { + const { user } = locals; console.log('accounts endpoint', user); diff --git a/src/routes/auth/idp/api/config.ts b/src/routes/auth/idp/api/config.ts new file mode 100644 index 0000000..61c12b5 --- /dev/null +++ b/src/routes/auth/idp/api/config.ts @@ -0,0 +1,33 @@ +import { json } from "@solidjs/router"; +import { APIEvent } from "@solidjs/start/server"; + +export const GET = async ({ request }: APIEvent) => { + console.log('config requested', request); + + return json({ + "accounts_endpoint": "/auth/idp/api/accounts", + "client_metadata_endpoint": "/auth/idp/api/metadata", + "id_assertion_endpoint": "/auth/idp/api/idtokens", + "disconnect_endpoint": "/auth/idp/api/disconnect", + "login_url": "/auth/idp", + "modes": { + "active": { + "supports_use_other_account": true + } + }, + "branding": { + "background_color": "#6200ee", + "color": "#ffffff", + "icons": [ + { + "url": "/images/favicon.dark.svg", + "size": 512 + }, + { + "url": "/images/favicon.light.svg", + "size": 512 + } + ] + } + }); +}; \ No newline at end of file diff --git a/src/routes/auth/idp/api/idtokens.ts b/src/routes/auth/idp/api/idtokens.ts index a6897c8..dc75617 100644 --- a/src/routes/auth/idp/api/idtokens.ts +++ b/src/routes/auth/idp/api/idtokens.ts @@ -3,9 +3,13 @@ import { APIEvent } from "@solidjs/start/server"; import { use, assertCsrf, assertApiSession } from "~/features/auth"; export const POST = use(assertCsrf, assertApiSession, async ({ request }: APIEvent) => { - console.log(request); + console.log('id token requested', request.url); return json({ token: 'THIS IS A BEAUTIFUL TOKEN', + }, { + headers: { + 'Set-Login': 'logged-in' + } }); }); \ No newline at end of file diff --git a/src/routes/auth/idp/api/login.ts b/src/routes/auth/idp/api/login.ts index ab160cc..94d3933 100644 --- a/src/routes/auth/idp/api/login.ts +++ b/src/routes/auth/idp/api/login.ts @@ -3,6 +3,8 @@ import { APIEvent } from "@solidjs/start/server"; import { getUser, signIn } from "~/features/auth"; export const POST = async ({ request }: APIEvent) => { + console.log('login requested', request.url); + const formData = await request.formData(); const username = formData.get('username'); const password = formData.get('password'); @@ -27,7 +29,9 @@ export const POST = async ({ request }: APIEvent) => { await signIn(user); - return redirect('/auth/client', { + const token = 'THIS IS MY AWESOME TOKEN'; + + return json({ token }, { headers: { 'Set-Login': 'logged-in', } diff --git a/src/routes/auth/idp/api/metadata.ts b/src/routes/auth/idp/api/metadata.ts index b9c2af3..691d0ce 100644 --- a/src/routes/auth/idp/api/metadata.ts +++ b/src/routes/auth/idp/api/metadata.ts @@ -2,6 +2,8 @@ import { json } from "@solidjs/router"; import { APIEvent } from "@solidjs/start/server"; export const GET = ({ request }: APIEvent) => { + console.log('metadata requested', request.url); + return json({ privacy_policy_url: '/privacy-policy.txt', terms_of_service_url: '/terms-of-service.txt', diff --git a/src/routes/auth/idp/api/user-info.ts b/src/routes/auth/idp/api/user-info.ts new file mode 100644 index 0000000..97c07a5 --- /dev/null +++ b/src/routes/auth/idp/api/user-info.ts @@ -0,0 +1,17 @@ +import { json } from "@solidjs/router"; +import { APIEvent } from "@solidjs/start/server"; +import { assertApiSession, use } from "~/features/auth"; + +export const GET = use(assertApiSession, async ({ locals }: APIEvent) => { + const { user } = locals; + + return json({ + id: user.id, + given_name: user.givenName, + name: `${user.givenName} ${user.familyName}`, + email: user.username, + picture: user.picture, + login_hints: [user.username], + approved_clients: user.approvedClients, + }); +}); \ No newline at end of file