|
| 1 | +<script lang="ts"> |
| 2 | + import { env } from '$env/dynamic/public'; |
| 3 | + import SensitiveValue from '$lib/SensitiveValue.svelte'; |
| 4 | + import type { PageData } from './$houdini'; |
| 5 | + interface Props { |
| 6 | + data: PageData; |
| 7 | + } |
| 8 | + const { data }: Props = $props(); |
| 9 | + const { PageApplication } = $derived(data); |
| 10 | +
|
| 11 | + function enumerate<T>(a: T[]): Array<[number, T]> { |
| 12 | + return Object.entries(a).map(([k, v]) => [parseInt(k), v]); |
| 13 | + } |
| 14 | +
|
| 15 | + function uris(allUris?: string | null): string[] { |
| 16 | + if (!allUris) return []; |
| 17 | + return allUris.split('\n'); |
| 18 | + } |
| 19 | +</script> |
| 20 | + |
| 21 | +{#if $PageApplication?.errors} |
| 22 | + <section class="errors"> |
| 23 | + <h2>Oops!</h2> |
| 24 | + <p>Il y a eu des erreurs</p> |
| 25 | + <ul> |
| 26 | + {#each $PageApplication.errors as { message }} |
| 27 | + <li>{message}</li> |
| 28 | + {/each} |
| 29 | + </ul> |
| 30 | + </section> |
| 31 | +{/if} |
| 32 | + |
| 33 | +{#if $PageApplication?.data?.application?.__typename === 'GenericError'} |
| 34 | + <section class="errors"> |
| 35 | + <h1>Ooops</h1> |
| 36 | + <p>{$PageApplication.data.application.detail}</p> |
| 37 | + <a href="/login">Connexion</a> |
| 38 | + </section> |
| 39 | +{/if} |
| 40 | + |
| 41 | +{#snippet copyable(value: string, sensitive = false)} |
| 42 | + <dd> |
| 43 | + <button |
| 44 | + onclick={() => { |
| 45 | + const clipboard = new Clipboard(); |
| 46 | + clipboard.writeText(value); |
| 47 | + }}>copier</button |
| 48 | + > |
| 49 | + {#if sensitive} |
| 50 | + <SensitiveValue>{value}</SensitiveValue> |
| 51 | + {:else} |
| 52 | + {value} |
| 53 | + {/if} |
| 54 | + </dd> |
| 55 | +{/snippet} |
| 56 | + |
| 57 | +{#if $PageApplication?.data?.application && $PageApplication.data.application.__typename === 'Application'} |
| 58 | + {@const app = $PageApplication.data.application} |
| 59 | + <h1> |
| 60 | + <img src={app.metaIcon} alt="Icone" class="logo" /> |
| 61 | + {app.name} |
| 62 | + </h1> |
| 63 | + {#if app.launchUrl} |
| 64 | + <a href={app.launchUrl}>https://{new URL(app.launchUrl).hostname}</a> |
| 65 | + {/if} |
| 66 | + <p class="desc">{app.metaDescription}</p> |
| 67 | + {#if app.oauth2Provider?.__typename === 'OAuth2Provider'} |
| 68 | + {@const authorizedUris = uris(app.oauth2Provider.redirectUris)} |
| 69 | + <dl> |
| 70 | + <dt>Client ID</dt> |
| 71 | + {@render copyable(app.oauth2Provider.clientId)} |
| 72 | + <dt>Client secret</dt> |
| 73 | + {@render copyable(app.oauth2Provider.clientSecret, true)} |
| 74 | + <dt>Allowed redirect URIs</dt> |
| 75 | + <dd class="redirecturis"> |
| 76 | + <small>Peut être un motif Regex d'URIs</small> |
| 77 | + {#if authorizedUris.includes('.*') && app.launchUrl} |
| 78 | + <p class="warn"> |
| 79 | + Attention: utiliser <code>.*</code> est dangereux, |
| 80 | + <button |
| 81 | + onclick={() => { |
| 82 | + document.querySelectorAll('.redirecturis input').forEach((node) => { |
| 83 | + if (!(node instanceof HTMLInputElement)) return; |
| 84 | + if (!app.launchUrl) return; |
| 85 | + if (node.value !== '.*') return; |
| 86 | + node.value = `https?://(localhost|${new URL(app.launchUrl).hostname}).*`; |
| 87 | + }); |
| 88 | + }}>utiliser localhost et {new URL(app.launchUrl).hostname}</button |
| 89 | + > |
| 90 | + </p> |
| 91 | + {/if} |
| 92 | + <form method="post" action="?/editAllowedURIs"> |
| 93 | + <ul> |
| 94 | + {#each enumerate(authorizedUris) as [i, uri]} |
| 95 | + <li> |
| 96 | + <input type="text" name="uri:{i}" value={uri} /> |
| 97 | + </li> |
| 98 | + {/each} |
| 99 | + <li class="new"> |
| 100 | + <input |
| 101 | + placeholder="Ajouter une URI" |
| 102 | + type="text" |
| 103 | + name="uri:{uris(app.oauth2Provider.redirectUris).length}" |
| 104 | + /> |
| 105 | + </li> |
| 106 | + </ul> |
| 107 | + <input type="hidden" name="providerid" value={app.oauth2Provider.pk} /> |
| 108 | + <button type="submit">enregistrer</button> |
| 109 | + </form> |
| 110 | + </dd> |
| 111 | + <p><em>Ne pas oublier le <code>/</code> à la fin des URLs 🙃</em></p> |
| 112 | + <dt>Authorize URL</dt> |
| 113 | + {@render copyable(`https://${env.PUBLIC_AUTHENTIK_INSTANCE}/o/authorize/`)} |
| 114 | + <dt>Token URL</dt> |
| 115 | + {@render copyable(`https://${env.PUBLIC_AUTHENTIK_INSTANCE}/o/token/`)} |
| 116 | + <dt>User-info URL</dt> |
| 117 | + {@render copyable(`https://${env.PUBLIC_AUTHENTIK_INSTANCE}/o/userinfo/`)} |
| 118 | + <dt>Logout URL</dt> |
| 119 | + {@render copyable(`https://${env.PUBLIC_AUTHENTIK_INSTANCE}/o/${app.slug}/end-session/`)} |
| 120 | + </dl> |
| 121 | + {/if} |
| 122 | +{/if} |
| 123 | + |
| 124 | +<style> |
| 125 | + section.errors { |
| 126 | + color: red; |
| 127 | + background-color: lightpink; |
| 128 | + } |
| 129 | +
|
| 130 | + .logo { |
| 131 | + height: 1.2em; |
| 132 | + } |
| 133 | +
|
| 134 | + h1 { |
| 135 | + display: flex; |
| 136 | + align-items: center; |
| 137 | + gap: 0 1ch; |
| 138 | + } |
| 139 | +
|
| 140 | + dd:not(.redirecturis) { |
| 141 | + display: flex; |
| 142 | + align-items: center; |
| 143 | + gap: 0 1ch; |
| 144 | + } |
| 145 | +
|
| 146 | + .redirecturis input { |
| 147 | + width: 40ch; |
| 148 | + } |
| 149 | +</style> |
0 commit comments