From 063e745313780b28929d6809dad20c656cd00b56 Mon Sep 17 00:00:00 2001 From: Skye Date: Sat, 26 Nov 2022 15:41:56 +0900 Subject: [PATCH] minor stuff --- .vscode/tasks.json | 19 +++++++++++++++++++ src/lib/KratosForm.svelte | 2 +- src/lib/server/APIClients.ts | 2 +- src/routes/+layout.server.ts | 5 +---- src/routes/consent/+page.server.ts | 7 +++++-- src/routes/error/+page.server.ts | 4 ++-- src/routes/error/+page.svelte | 2 -- src/routes/logout/+page.server.ts | 4 ++-- src/routes/settings/+page.server.ts | 2 +- 9 files changed, 32 insertions(+), 15 deletions(-) create mode 100644 .vscode/tasks.json diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..bc97916 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,19 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "type": "npm", + "script": "lint", + "problemMatcher": [], + "label": "npm: lint", + "detail": "prettier --plugin-search-dir . --check . && eslint ." + }, + { + "type": "npm", + "script": "format", + "problemMatcher": [], + "label": "npm: format", + "detail": "prettier --plugin-search-dir . --write ." + } + ] +} diff --git a/src/lib/KratosForm.svelte b/src/lib/KratosForm.svelte index a6a8e76..474dff5 100644 --- a/src/lib/KratosForm.svelte +++ b/src/lib/KratosForm.svelte @@ -2,7 +2,7 @@ import { browser } from '$app/environment'; import { XCircleIcon, AlertCircleIcon, CheckCircleIcon } from 'svelte-feather-icons'; - import type { UiContainer, UiNodeInputAttributesTypeEnum } from '@ory/client'; + import type { UiContainer } from '@ory/client'; import { getNodeLabel, isUiNodeAnchorAttributes, diff --git a/src/lib/server/APIClients.ts b/src/lib/server/APIClients.ts index e908aa1..1aa66cc 100644 --- a/src/lib/server/APIClients.ts +++ b/src/lib/server/APIClients.ts @@ -1,6 +1,6 @@ import { env } from '$env/dynamic/private'; import { Configuration as HydraConfiguration, OAuth2Api } from '@ory/hydra-client'; -import { Configuration as KratosConfiguration, V0alpha2Api, ReadApi } from '@ory/client'; +import { Configuration as KratosConfiguration, V0alpha2Api } from '@ory/client'; export const HydraAdminApi = new OAuth2Api( new HydraConfiguration({ basePath: env.HYDRA_ADMIN_API diff --git a/src/routes/+layout.server.ts b/src/routes/+layout.server.ts index ba98a67..7c81aec 100644 --- a/src/routes/+layout.server.ts +++ b/src/routes/+layout.server.ts @@ -3,10 +3,7 @@ import { KratosPublicApi } from '$lib/server/APIClients.js'; export const load: LayoutServerLoad = async ({ request }) => { try { - const current_user = await KratosPublicApi.toSession( - undefined, - request.headers.get('Cookie') ?? undefined - ); + await KratosPublicApi.toSession(undefined, request.headers.get('Cookie') ?? undefined); return { logged_in: true, logout_url: ( diff --git a/src/routes/consent/+page.server.ts b/src/routes/consent/+page.server.ts index 63b6911..14330e8 100644 --- a/src/routes/consent/+page.server.ts +++ b/src/routes/consent/+page.server.ts @@ -60,15 +60,18 @@ async function acceptRequest( user: AxiosResponse, consent_challenge: string ) { - let extra_grants: Record = {}; + const extra_grants: Record = {}; if (consent_request.data.requested_scope?.includes('email')) { extra_grants.email = user.data.traits.email; extra_grants.email_verified = user.data.verifiable_addresses?.find((e) => e.value == user.data.traits.email)?.verified == true; } + if (consent_request.data.requested_scope?.includes('profile')) { + extra_grants.username = user.data.traits.username; + } // Put more scopes here if needs arise - let response = await HydraAdminApi.acceptOAuth2ConsentRequest(consent_challenge, { + const response = await HydraAdminApi.acceptOAuth2ConsentRequest(consent_challenge, { grant_scope: consent_request.data.requested_scope, grant_access_token_audience: consent_request.data.requested_access_token_audience, remember: true, diff --git a/src/routes/error/+page.server.ts b/src/routes/error/+page.server.ts index 126a0f8..a2e8ae3 100644 --- a/src/routes/error/+page.server.ts +++ b/src/routes/error/+page.server.ts @@ -1,9 +1,9 @@ import type { PageServerLoad } from './$types'; import { KratosPublicApi } from '$lib/server/APIClients.js'; import { redirect } from '@sveltejs/kit'; -import { DEFAULT_REDIRECT_URL, KRATOS_PUBLIC_URL } from '$lib/server/config'; +import { DEFAULT_REDIRECT_URL } from '$lib/server/config'; -export const load: PageServerLoad = async ({ url, request }) => { +export const load: PageServerLoad = async ({ url }) => { const id = url.searchParams.get('id'); if (id == undefined) { diff --git a/src/routes/error/+page.svelte b/src/routes/error/+page.svelte index 90d69d9..0c169ee 100644 --- a/src/routes/error/+page.svelte +++ b/src/routes/error/+page.svelte @@ -1,6 +1,4 @@ diff --git a/src/routes/logout/+page.server.ts b/src/routes/logout/+page.server.ts index 67f174f..286aa3a 100644 --- a/src/routes/logout/+page.server.ts +++ b/src/routes/logout/+page.server.ts @@ -47,7 +47,7 @@ export const actions: Actions = { const logout_token = await KratosPublicApi.createSelfServiceLogoutFlowUrlForBrowsers( request.headers.get('Cookie') ?? undefined ); - let logout_url = new URL(logout_token.data.logout_url); + const logout_url = new URL(logout_token.data.logout_url); const response = await HydraAdminApi.acceptOAuth2LogoutRequest(logout_challenge); logout_url.searchParams.append('return_to', response.data.redirect_to); throw redirect(303, logout_url.toString()); @@ -57,7 +57,7 @@ export const actions: Actions = { if (typeof logout_challenge != 'string') { throw error(400, 'logout_challenge is invalid'); } - const response = await HydraAdminApi.rejectOAuth2LogoutRequest(logout_challenge); + await HydraAdminApi.rejectOAuth2LogoutRequest(logout_challenge); throw redirect(303, DEFAULT_REDIRECT_URL); } }; diff --git a/src/routes/settings/+page.server.ts b/src/routes/settings/+page.server.ts index ec416b5..10906f3 100644 --- a/src/routes/settings/+page.server.ts +++ b/src/routes/settings/+page.server.ts @@ -2,7 +2,7 @@ import type { PageServerLoad } from './$types'; import { KratosAdminApi, KratosPublicApi } from '$lib/server/APIClients.js'; import { redirect } from '@sveltejs/kit'; import { KRATOS_PUBLIC_URL } from '$lib/server/config'; -import type { SelfServiceLoginFlow, SelfServiceSettingsFlow } from '@ory/client'; +import type { SelfServiceSettingsFlow } from '@ory/client'; export const load: PageServerLoad = async ({ url, request }) => { const flow = url.searchParams.get('flow');