minor stuff
This commit is contained in:
parent
8e3bea9429
commit
063e745313
9 changed files with 32 additions and 15 deletions
19
.vscode/tasks.json
vendored
Normal file
19
.vscode/tasks.json
vendored
Normal 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 ."
|
||||
}
|
||||
]
|
||||
}
|
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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: (
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
<script lang="ts">
|
||||
import { XCircleIcon } from 'svelte-feather-icons';
|
||||
|
||||
import type { PageData } from './$types';
|
||||
export let data: PageData;
|
||||
</script>
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
};
|
||||
|
|
|
@ -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');
|
||||
|
|
Loading…
Reference in a new issue