1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import { html, htmlResponse, Layout } from "https://esm.town/v/postpostscript/htmlComponentLibrary";
import { getRedirectUrl } from "https://esm.town/v/postpostscript/moduleHighlightValueLink";
import { MyFooter } from "https://esm.town/v/postpostscript/MyFooter";
import { vueSfcInline } from "https://esm.town/v/postpostscript/vue";
export const GenerateJWKSEnv = vueSfcInline`
<script setup lang="ts">
import { ref, computed, onMounted } from "vue";
import { exportJWK, generateKeyPair } from "https://esm.sh/jose@v5.2.2";
import fileSaver from "https://esm.sh/file-saver@v2.0.5";
const { default: saveAs } = fileSaver;
function outputKey(key) {
return JSON.stringify({
keys: [
{
alg: alg.value,
...key,
}
]
})
}
async function generate() {
const { publicKey, privateKey } = await generateKeyPair(alg.value, {
extractable: true,
});
publicJWK.value = await exportJWK(publicKey);
privateJWK.value = await exportJWK(privateKey);
file.value = \`
\${prefix.value}_PUBLIC=\${outputKey(publicJWK.value)}
\${prefix.value}_PRIVATE=\${outputKey(privateJWK.value)}
\`.trim()
if (!filenameChanged.value) {
filename.value = prefix.value + ".env";
}
selected.value = false;
}
const qs = new URLSearchParams(window.location.href.split("?")[1])
const alg = ref("RS512");
const prefix = ref(qs.get("prefix") ?? "JWKS");
const filename = ref<string>(prefix.value + ".env");
const file = ref<string>();
const publicJWK = ref();
const privateJWK = ref();
const filenameChanged = ref(false);
const selected = ref(false);
const blob = computed(() => {
return new Blob([file.value], { type: 'text/plain;charset=utf-8' });
});
onMounted(generate);
</script>
<template>
<form class="left" @submit.prevent="generate">
<label>
Prefix:
<input v-model="prefix" name="prefix" />
</label>
<button>
Regenerate
</button>
</form>
<form class="right" @submit.prevent="saveAs(blob, filename)">
<label>
Filename:
<input v-model="filename" name="filename" @change="filenameChanged = true" />
</label>
<button>
Download as {{ filename }}
</button>
</form>
<div class="clearfix"></div>
<label>
<h2>
Your env file: {{ filename }}
</h2>
<div class="textarea-wrapper">
<textarea ref="$textarea" v-model="file" @focus="!selected && $event.target.select(); selected = true"></textarea>
</div>
</label>
</template>
<style scoped>
.left {
float: left;
}
.right {
@media screen and (min-width: 465px) {
float: right;