@geektr.cloud/acrux-auth 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +796 -2
- package/package.json +59 -3
- package/src/components/AuthError.vue +45 -0
- package/src/components/AuthLogin.vue +201 -0
- package/src/components/PubKeyClient.vue +477 -0
- package/src/index.ts +82 -0
- package/src/next.ts +22 -0
- package/src/passkey-client.ts +159 -0
- package/src/passkey-metadata.ts +56 -0
- package/src/pubkey-client.ts +183 -0
- package/src/pubkey-proof.ts +179 -0
- package/src/pubkey-transport.ts +107 -0
- package/src/pubkey-types.ts +41 -0
- package/src/server/http.ts +27 -0
- package/src/server/identity.ts +22 -0
- package/src/server/index.ts +10 -0
- package/src/server/passkey/challenge.ts +70 -0
- package/src/server/passkey/config.ts +97 -0
- package/src/server/passkey/index.ts +10 -0
- package/src/server/passkey/routes.ts +310 -0
- package/src/server/passkey/store.ts +84 -0
- package/src/server/provider.ts +90 -0
- package/src/server/providers/cloudflare.ts +83 -0
- package/src/server/providers/custom.ts +47 -0
- package/src/server/providers/github.ts +112 -0
- package/src/server/providers/google.ts +45 -0
- package/src/server/providers/index.ts +4 -0
- package/src/server/pubkey/errors.ts +32 -0
- package/src/server/pubkey/fixtures.ts +156 -0
- package/src/server/pubkey/http.ts +91 -0
- package/src/server/pubkey/index.ts +10 -0
- package/src/server/pubkey/keys.ts +166 -0
- package/src/server/pubkey/resolve.ts +189 -0
- package/src/server/pubkey/resolver.ts +111 -0
- package/src/server/pubkey/verify.ts +119 -0
- package/src/server/pubkey/wkd.ts +78 -0
- package/src/server/pubkey-passkey/index.ts +14 -0
- package/src/server/pubkey-passkey/routes.ts +260 -0
- package/src/server/routes.ts +340 -0
- package/src/server/session.ts +86 -0
- package/src/server/userpass.ts +104 -0
- package/src/types.ts +82 -0
package/package.json
CHANGED
|
@@ -1,6 +1,62 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@geektr.cloud/acrux-auth",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"description": "
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "认证 UI 与 Hono 服务端工具:userpass、signed session、OIDC / OAuth provider、Passkey。",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/geektr-cloud/acrux.git",
|
|
10
|
+
"directory": "packages/acrux-auth"
|
|
11
|
+
},
|
|
12
|
+
"homepage": "https://acrux.geektr.cloud/",
|
|
13
|
+
"files": [
|
|
14
|
+
"src",
|
|
15
|
+
"!**/*.test.ts",
|
|
16
|
+
"!**/__fixtures__/",
|
|
17
|
+
"README.md",
|
|
18
|
+
"LICENSE"
|
|
19
|
+
],
|
|
20
|
+
"publishConfig": {
|
|
21
|
+
"access": "public",
|
|
22
|
+
"registry": "https://registry.npmjs.org"
|
|
23
|
+
},
|
|
24
|
+
"exports": {
|
|
25
|
+
".": "./src/index.ts",
|
|
26
|
+
"./pubkey-types": "./src/pubkey-types.ts",
|
|
27
|
+
"./server": "./src/server/index.ts"
|
|
28
|
+
},
|
|
29
|
+
"prettier": "@geektr.cloud/acrux-eslint-config/prettier",
|
|
30
|
+
"engines": {
|
|
31
|
+
"node": "^22.12.0 || ^24.0.0 || >=26.0.0"
|
|
32
|
+
},
|
|
33
|
+
"dependencies": {
|
|
34
|
+
"@simplewebauthn/server": "^14.1.0",
|
|
35
|
+
"openid-client": "^6.9.1",
|
|
36
|
+
"openpgp": "^6.3.3",
|
|
37
|
+
"webauthn-polyfills": "0.1.7",
|
|
38
|
+
"@geektr.cloud/acrux-ui": "0.1.0"
|
|
39
|
+
},
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"eslint": "^10.16.0",
|
|
42
|
+
"hono": "^4.13.23",
|
|
43
|
+
"prettier": "3.10.1",
|
|
44
|
+
"typescript": "~5.9.3",
|
|
45
|
+
"vitest": "^5.1.2",
|
|
46
|
+
"vue": "^3.5.46",
|
|
47
|
+
"vue-tsc": "3.3.13",
|
|
48
|
+
"zod": "^4.6.7",
|
|
49
|
+
"@geektr.cloud/acrux-eslint-config": "0.1.0"
|
|
50
|
+
},
|
|
51
|
+
"peerDependencies": {
|
|
52
|
+
"hono": "^4.13.23",
|
|
53
|
+
"vue": "^3.5.46",
|
|
54
|
+
"zod": "^4.6.7"
|
|
55
|
+
},
|
|
56
|
+
"scripts": {
|
|
57
|
+
"type-check": "vue-tsc --noEmit -p tsconfig.json",
|
|
58
|
+
"test": "vitest",
|
|
59
|
+
"test:run": "vitest run",
|
|
60
|
+
"lint": "eslint --fix ./src && prettier --write ./src"
|
|
61
|
+
}
|
|
6
62
|
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { nextTick, onMounted, ref, watch } from "vue";
|
|
3
|
+
import { Notice } from "@geektr.cloud/acrux-ui/display";
|
|
4
|
+
|
|
5
|
+
const props = withDefaults(
|
|
6
|
+
defineProps<{
|
|
7
|
+
id: string;
|
|
8
|
+
message?: string | null;
|
|
9
|
+
}>(),
|
|
10
|
+
{
|
|
11
|
+
message: "",
|
|
12
|
+
},
|
|
13
|
+
);
|
|
14
|
+
|
|
15
|
+
defineSlots<{
|
|
16
|
+
default?: (props: { message: string }) => unknown;
|
|
17
|
+
}>();
|
|
18
|
+
|
|
19
|
+
const container = ref<HTMLElement | null>(null);
|
|
20
|
+
|
|
21
|
+
const focus = async () => {
|
|
22
|
+
await nextTick();
|
|
23
|
+
container.value?.focus();
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
watch(
|
|
27
|
+
() => props.message,
|
|
28
|
+
(value, previous) => {
|
|
29
|
+
if (value && !previous) void focus();
|
|
30
|
+
},
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
onMounted(() => {
|
|
34
|
+
if (props.message) void focus();
|
|
35
|
+
});
|
|
36
|
+
</script>
|
|
37
|
+
|
|
38
|
+
<template>
|
|
39
|
+
<div :id="id" ref="container" data-slot="error" role="alert" tabindex="-1">
|
|
40
|
+
<slot v-if="message" :message="message">
|
|
41
|
+
<!-- The wrapper owns the live region; avoid a nested alert announcement. -->
|
|
42
|
+
<Notice tone="error" role="status" aria-live="off">{{ message }}</Notice>
|
|
43
|
+
</slot>
|
|
44
|
+
</div>
|
|
45
|
+
</template>
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { computed, useId } from "vue";
|
|
3
|
+
import { Text } from "@geektr.cloud/acrux-ui/base";
|
|
4
|
+
import { Button } from "@geektr.cloud/acrux-ui/ui/button";
|
|
5
|
+
import { Card } from "@geektr.cloud/acrux-ui/ui/card";
|
|
6
|
+
import { Input } from "@geektr.cloud/acrux-ui/ui/input";
|
|
7
|
+
import { Label } from "@geektr.cloud/acrux-ui/ui/label";
|
|
8
|
+
import type { AuthLoginEmits, AuthLoginProps, AuthLoginSlots, AuthLoginSubmitPayload } from "../types";
|
|
9
|
+
import AuthError from "./AuthError.vue";
|
|
10
|
+
|
|
11
|
+
const props = withDefaults(defineProps<AuthLoginProps>(), {
|
|
12
|
+
username: "",
|
|
13
|
+
password: "",
|
|
14
|
+
loading: false,
|
|
15
|
+
disabled: false,
|
|
16
|
+
error: null,
|
|
17
|
+
title: "登录",
|
|
18
|
+
description: "使用用户名和密码登录",
|
|
19
|
+
usernameLabel: "用户名",
|
|
20
|
+
passwordLabel: "密码",
|
|
21
|
+
submitLabel: "登录",
|
|
22
|
+
loadingLabel: "登录中…",
|
|
23
|
+
providersLabel: "或使用第三方账号",
|
|
24
|
+
separatorLabel: "或",
|
|
25
|
+
name: "auth",
|
|
26
|
+
providers: () => [],
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
const emit = defineEmits<AuthLoginEmits>();
|
|
30
|
+
defineSlots<AuthLoginSlots>();
|
|
31
|
+
|
|
32
|
+
const username = defineModel<string>("username", { default: "" });
|
|
33
|
+
const password = defineModel<string>("password", { default: "" });
|
|
34
|
+
|
|
35
|
+
const uid = useId();
|
|
36
|
+
const usernameId = computed(() => `${props.name}-${uid}-username`);
|
|
37
|
+
const passwordId = computed(() => `${props.name}-${uid}-password`);
|
|
38
|
+
const errorId = computed(() => `${props.name}-${uid}-error`);
|
|
39
|
+
const errorMessage = computed(() => props.error ?? "");
|
|
40
|
+
const isBusy = computed(() => props.loading || props.disabled);
|
|
41
|
+
|
|
42
|
+
let submitLock = false;
|
|
43
|
+
|
|
44
|
+
const setUsername = (value: string) => {
|
|
45
|
+
username.value = value;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const setPassword = (value: string) => {
|
|
49
|
+
password.value = value;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const handleSubmit = () => {
|
|
53
|
+
if (submitLock || isBusy.value) return;
|
|
54
|
+
if (!username.value || !password.value) return;
|
|
55
|
+
|
|
56
|
+
submitLock = true;
|
|
57
|
+
const payload: AuthLoginSubmitPayload = {
|
|
58
|
+
username: username.value,
|
|
59
|
+
password: password.value,
|
|
60
|
+
};
|
|
61
|
+
emit("submit", payload);
|
|
62
|
+
// 父组件通常立刻把 loading 设为 true;这个锁只挡住同一事件循环内的重复提交。
|
|
63
|
+
setTimeout(() => {
|
|
64
|
+
submitLock = false;
|
|
65
|
+
}, 0);
|
|
66
|
+
};
|
|
67
|
+
</script>
|
|
68
|
+
|
|
69
|
+
<template>
|
|
70
|
+
<div data-slot="auth-login" class="w-full">
|
|
71
|
+
<slot name="before" />
|
|
72
|
+
|
|
73
|
+
<Card data-slot="card" class="gap-0 p-5">
|
|
74
|
+
<slot name="header">
|
|
75
|
+
<header data-slot="header" class="space-y-1">
|
|
76
|
+
<slot name="title">
|
|
77
|
+
<Text variant="h1">{{ title }}</Text>
|
|
78
|
+
</slot>
|
|
79
|
+
<slot name="description">
|
|
80
|
+
<Text v-if="description" variant="lead">{{ description }}</Text>
|
|
81
|
+
</slot>
|
|
82
|
+
</header>
|
|
83
|
+
</slot>
|
|
84
|
+
|
|
85
|
+
<AuthError :id="errorId" :message="errorMessage" :class="errorMessage ? 'mt-4' : undefined">
|
|
86
|
+
<template v-if="$slots.error" #default="{ message }">
|
|
87
|
+
<slot name="error" :message="message" />
|
|
88
|
+
</template>
|
|
89
|
+
</AuthError>
|
|
90
|
+
|
|
91
|
+
<slot name="before-form" />
|
|
92
|
+
|
|
93
|
+
<form data-slot="form" class="mt-4 grid gap-3" :aria-busy="isBusy || undefined" @submit.prevent="handleSubmit">
|
|
94
|
+
<slot
|
|
95
|
+
name="username"
|
|
96
|
+
:id="usernameId"
|
|
97
|
+
:field-name="name"
|
|
98
|
+
:value="username"
|
|
99
|
+
:set-value="setUsername"
|
|
100
|
+
:disabled="isBusy"
|
|
101
|
+
:invalid="Boolean(errorMessage)"
|
|
102
|
+
>
|
|
103
|
+
<div data-slot="username-field">
|
|
104
|
+
<Label :for="usernameId">{{ usernameLabel }}</Label>
|
|
105
|
+
<Input
|
|
106
|
+
:id="usernameId"
|
|
107
|
+
v-model="username"
|
|
108
|
+
:name="`${name}-username`"
|
|
109
|
+
:disabled="isBusy"
|
|
110
|
+
:aria-invalid="errorMessage ? 'true' : undefined"
|
|
111
|
+
:aria-describedby="errorMessage ? errorId : undefined"
|
|
112
|
+
type="text"
|
|
113
|
+
autocomplete="username"
|
|
114
|
+
autocapitalize="none"
|
|
115
|
+
spellcheck="false"
|
|
116
|
+
required
|
|
117
|
+
class="mt-1.5"
|
|
118
|
+
/>
|
|
119
|
+
</div>
|
|
120
|
+
</slot>
|
|
121
|
+
|
|
122
|
+
<slot
|
|
123
|
+
name="password"
|
|
124
|
+
:id="passwordId"
|
|
125
|
+
:field-name="name"
|
|
126
|
+
:value="password"
|
|
127
|
+
:set-value="setPassword"
|
|
128
|
+
:disabled="isBusy"
|
|
129
|
+
:invalid="Boolean(errorMessage)"
|
|
130
|
+
>
|
|
131
|
+
<div data-slot="password-field">
|
|
132
|
+
<Label :for="passwordId">{{ passwordLabel }}</Label>
|
|
133
|
+
<Input
|
|
134
|
+
:id="passwordId"
|
|
135
|
+
v-model="password"
|
|
136
|
+
:name="`${name}-password`"
|
|
137
|
+
:disabled="isBusy"
|
|
138
|
+
:aria-invalid="errorMessage ? 'true' : undefined"
|
|
139
|
+
:aria-describedby="errorMessage ? errorId : undefined"
|
|
140
|
+
type="password"
|
|
141
|
+
autocomplete="current-password"
|
|
142
|
+
required
|
|
143
|
+
class="mt-1.5"
|
|
144
|
+
/>
|
|
145
|
+
</div>
|
|
146
|
+
</slot>
|
|
147
|
+
|
|
148
|
+
<slot name="userpass" :loading="loading" :disabled="isBusy" />
|
|
149
|
+
|
|
150
|
+
<slot name="userpass-actions" :loading="loading" :disabled="isBusy">
|
|
151
|
+
<Button data-slot="submit" type="submit" :disabled="isBusy" class="w-full">
|
|
152
|
+
{{ loading ? loadingLabel : submitLabel }}
|
|
153
|
+
</Button>
|
|
154
|
+
</slot>
|
|
155
|
+
</form>
|
|
156
|
+
|
|
157
|
+
<slot name="after-form" />
|
|
158
|
+
|
|
159
|
+
<section v-if="providers.length > 0" data-slot="providers" class="mt-5" :aria-label="providersLabel">
|
|
160
|
+
<slot name="separator">
|
|
161
|
+
<div data-slot="separator" class="flex items-center gap-3" role="separator" aria-orientation="horizontal">
|
|
162
|
+
<span class="h-px flex-1 bg-border" aria-hidden="true" />
|
|
163
|
+
<Text as="span" variant="small" class="uppercase tracking-wide text-muted-foreground">
|
|
164
|
+
{{ separatorLabel }}
|
|
165
|
+
</Text>
|
|
166
|
+
<span class="h-px flex-1 bg-border" aria-hidden="true" />
|
|
167
|
+
</div>
|
|
168
|
+
</slot>
|
|
169
|
+
|
|
170
|
+
<slot name="providers">
|
|
171
|
+
<Text variant="list" data-slot="provider-list" role="list" class="mt-3 ml-0 grid list-none gap-2 [&>li]:mt-0">
|
|
172
|
+
<li v-for="(provider, index) in providers" :key="provider.id">
|
|
173
|
+
<slot name="provider" :provider="provider" :index="index">
|
|
174
|
+
<Button as-child variant="outline" class="w-full">
|
|
175
|
+
<a :href="provider.href" data-slot="provider-link">
|
|
176
|
+
<svg
|
|
177
|
+
aria-hidden="true"
|
|
178
|
+
class="size-3.5"
|
|
179
|
+
viewBox="0 0 24 24"
|
|
180
|
+
fill="none"
|
|
181
|
+
stroke="currentColor"
|
|
182
|
+
stroke-width="2"
|
|
183
|
+
stroke-linecap="square"
|
|
184
|
+
>
|
|
185
|
+
<path d="M7 17 17 7M9 7h8v8" />
|
|
186
|
+
</svg>
|
|
187
|
+
<Text as="span">{{ provider.label }}</Text>
|
|
188
|
+
</a>
|
|
189
|
+
</Button>
|
|
190
|
+
</slot>
|
|
191
|
+
</li>
|
|
192
|
+
</Text>
|
|
193
|
+
</slot>
|
|
194
|
+
</section>
|
|
195
|
+
|
|
196
|
+
<slot name="footer" />
|
|
197
|
+
</Card>
|
|
198
|
+
|
|
199
|
+
<slot name="after" />
|
|
200
|
+
</div>
|
|
201
|
+
</template>
|