minor stuff

This commit is contained in:
Skye 2022-11-26 15:41:56 +09:00
parent 8e3bea9429
commit 063e745313
Signed by: me
GPG key ID: 0104BC05F41B77B8
9 changed files with 32 additions and 15 deletions

19
.vscode/tasks.json vendored Normal file
View file

@ -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 ."
}
]
}

View file

@ -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,

View file

@ -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

View file

@ -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: (

View file

@ -60,15 +60,18 @@ async function acceptRequest(
user: AxiosResponse<Identity>,
consent_challenge: string
) {
let extra_grants: Record<string, any> = {};
const extra_grants: Record<string, any> = {};
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,

View file

@ -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) {

View file

@ -1,6 +1,4 @@
<script lang="ts">
import { XCircleIcon } from 'svelte-feather-icons';
import type { PageData } from './$types';
export let data: PageData;
</script>

View file

@ -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);
}
};

View file

@ -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');