@atproto/oauth-provider 0.21.3 → 0.22.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/CHANGELOG.md +25 -0
- package/dist/account/account-manager.d.ts +1 -1
- package/dist/account/account-manager.d.ts.map +1 -1
- package/dist/account/account-manager.js +3 -1
- package/dist/account/account-manager.js.map +1 -1
- package/dist/customization/background.d.ts +13 -0
- package/dist/customization/background.d.ts.map +1 -0
- package/dist/customization/background.js +7 -0
- package/dist/customization/background.js.map +1 -0
- package/dist/customization/branding.d.ts +19 -57
- package/dist/customization/branding.d.ts.map +1 -1
- package/dist/customization/branding.js +2 -0
- package/dist/customization/branding.js.map +1 -1
- package/dist/customization/build-customization-css.d.ts.map +1 -1
- package/dist/customization/build-customization-css.js +29 -25
- package/dist/customization/build-customization-css.js.map +1 -1
- package/dist/customization/colors.d.ts +1 -31
- package/dist/customization/colors.d.ts.map +1 -1
- package/dist/customization/colors.js +3 -21
- package/dist/customization/colors.js.map +1 -1
- package/dist/customization/customization.d.ts +27 -83
- package/dist/customization/customization.d.ts.map +1 -1
- package/dist/lib/util/color.d.ts +0 -1
- package/dist/lib/util/color.d.ts.map +1 -1
- package/dist/lib/util/color.js +0 -28
- package/dist/lib/util/color.js.map +1 -1
- package/dist/oauth-hooks.d.ts +6 -4
- package/dist/oauth-hooks.d.ts.map +1 -1
- package/dist/oauth-hooks.js.map +1 -1
- package/dist/router/assets/assets.js +1 -1
- package/dist/router/assets/assets.js.map +1 -1
- package/dist/router/create-api-middleware.d.ts.map +1 -1
- package/dist/router/create-api-middleware.js +5 -2
- package/dist/router/create-api-middleware.js.map +1 -1
- package/package.json +5 -5
- package/dist/types/color-hue.d.ts +0 -3
- package/dist/types/color-hue.d.ts.map +0 -1
- package/dist/types/color-hue.js +0 -3
- package/dist/types/color-hue.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"colors.js","sourceRoot":"","sources":["../../src/customization/colors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AACvB,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;
|
|
1
|
+
{"version":3,"file":"colors.js","sourceRoot":"","sources":["../../src/customization/colors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AACvB,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AAEtD,MAAM,CAAC,MAAM,WAAW,GAAG;IACzB,SAAS;IACT,OAAO;IACP,SAAS;IACT,MAAM;IACN,SAAS;CACD,CAAA;AAGV,+EAA+E;AAC/E,uEAAuE;AACvE,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,CAAC,MAAM,CAClC,MAAM,CAAC,WAAW,CAChB,WAAW,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,cAAc,CAAC,QAAQ,EAAE,CAAC,CAAC,CACF,CAC7D,CAAA","sourcesContent":["import { z } from 'zod'\nimport { rgbColorSchema } from '../types/rgb-color.js'\n\nexport const COLOR_NAMES = [\n 'primary',\n 'error',\n 'warning',\n 'info',\n 'success',\n] as const\nexport type ColorName = (typeof COLOR_NAMES)[number]\n\n// Each colour is a single RGB value. Only the primary colour gets a foreground\n// (--primary-foreground), computed as black or white by WCAG contrast.\nexport const colorsSchema = z.object(\n Object.fromEntries(\n COLOR_NAMES.map((name) => [name, rgbColorSchema.optional()]),\n ) as Record<ColorName, z.ZodOptional<typeof rgbColorSchema>>,\n)\n\nexport type Colors = z.infer<typeof colorsSchema>\n"]}
|
|
@@ -11,48 +11,28 @@ export declare const customizationSchema: z.ZodObject<{
|
|
|
11
11
|
branding: z.ZodOptional<z.ZodObject<{
|
|
12
12
|
name: z.ZodOptional<z.ZodString>;
|
|
13
13
|
logo: z.ZodOptional<z.ZodString>;
|
|
14
|
-
colors: z.ZodOptional<z.ZodObject<z.
|
|
15
|
-
light: z.ZodOptional<z.ZodEffects<z.ZodString, import("../lib/util/color.js").RgbColor, string>>;
|
|
16
|
-
dark: z.ZodOptional<z.ZodEffects<z.ZodString, import("../lib/util/color.js").RgbColor, string>>;
|
|
17
|
-
contrastSaturation: z.ZodOptional<z.ZodNumber>;
|
|
18
|
-
}, Record<"error" | "info" | "primary" | "success" | "warning", z.ZodOptional<z.ZodEffects<z.ZodString, import("../lib/util/color.js").RgbColor, string>>>>, Record<"errorContrast" | "infoContrast" | "primaryContrast" | "successContrast" | "warningContrast", z.ZodOptional<z.ZodEffects<z.ZodString, import("../lib/util/color.js").RgbColor, string>>>>, Record<"errorHue" | "infoHue" | "primaryHue" | "successHue" | "warningHue", z.ZodOptional<z.ZodNumber>>>, "strip", z.ZodTypeAny, {
|
|
19
|
-
light?: import("../lib/util/color.js").RgbColor | undefined;
|
|
20
|
-
dark?: import("../lib/util/color.js").RgbColor | undefined;
|
|
21
|
-
contrastSaturation?: number | undefined;
|
|
14
|
+
colors: z.ZodOptional<z.ZodObject<Record<"error" | "info" | "primary" | "success" | "warning", z.ZodOptional<z.ZodEffects<z.ZodString, import("../lib/util/color.js").RgbColor, string>>>, "strip", z.ZodTypeAny, {
|
|
22
15
|
error?: import("../lib/util/color.js").RgbColor | undefined;
|
|
23
|
-
errorContrast?: import("../lib/util/color.js").RgbColor | undefined;
|
|
24
|
-
errorHue?: number | undefined;
|
|
25
16
|
info?: import("../lib/util/color.js").RgbColor | undefined;
|
|
26
|
-
infoContrast?: import("../lib/util/color.js").RgbColor | undefined;
|
|
27
|
-
infoHue?: number | undefined;
|
|
28
17
|
primary?: import("../lib/util/color.js").RgbColor | undefined;
|
|
29
|
-
primaryContrast?: import("../lib/util/color.js").RgbColor | undefined;
|
|
30
|
-
primaryHue?: number | undefined;
|
|
31
18
|
success?: import("../lib/util/color.js").RgbColor | undefined;
|
|
32
|
-
successContrast?: import("../lib/util/color.js").RgbColor | undefined;
|
|
33
|
-
successHue?: number | undefined;
|
|
34
19
|
warning?: import("../lib/util/color.js").RgbColor | undefined;
|
|
35
|
-
warningContrast?: import("../lib/util/color.js").RgbColor | undefined;
|
|
36
|
-
warningHue?: number | undefined;
|
|
37
20
|
}, {
|
|
38
|
-
light?: string | undefined;
|
|
39
|
-
dark?: string | undefined;
|
|
40
|
-
contrastSaturation?: number | undefined;
|
|
41
21
|
error?: string | undefined;
|
|
42
|
-
errorContrast?: string | undefined;
|
|
43
|
-
errorHue?: number | undefined;
|
|
44
22
|
info?: string | undefined;
|
|
45
|
-
infoContrast?: string | undefined;
|
|
46
|
-
infoHue?: number | undefined;
|
|
47
23
|
primary?: string | undefined;
|
|
48
|
-
primaryContrast?: string | undefined;
|
|
49
|
-
primaryHue?: number | undefined;
|
|
50
24
|
success?: string | undefined;
|
|
51
|
-
successContrast?: string | undefined;
|
|
52
|
-
successHue?: number | undefined;
|
|
53
25
|
warning?: string | undefined;
|
|
54
|
-
|
|
55
|
-
|
|
26
|
+
}>>;
|
|
27
|
+
background: z.ZodOptional<z.ZodObject<{
|
|
28
|
+
light: z.ZodOptional<z.ZodString>;
|
|
29
|
+
dark: z.ZodOptional<z.ZodString>;
|
|
30
|
+
}, "strip", z.ZodTypeAny, {
|
|
31
|
+
light?: string | undefined;
|
|
32
|
+
dark?: string | undefined;
|
|
33
|
+
}, {
|
|
34
|
+
light?: string | undefined;
|
|
35
|
+
dark?: string | undefined;
|
|
56
36
|
}>>;
|
|
57
37
|
links: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
58
38
|
title: z.ZodUnion<[z.ZodString, z.ZodRecord<z.ZodString, z.ZodOptional<z.ZodString>>]>;
|
|
@@ -71,24 +51,15 @@ export declare const customizationSchema: z.ZodObject<{
|
|
|
71
51
|
name?: string | undefined;
|
|
72
52
|
logo?: string | undefined;
|
|
73
53
|
colors?: {
|
|
74
|
-
light?: import("../lib/util/color.js").RgbColor | undefined;
|
|
75
|
-
dark?: import("../lib/util/color.js").RgbColor | undefined;
|
|
76
|
-
contrastSaturation?: number | undefined;
|
|
77
54
|
error?: import("../lib/util/color.js").RgbColor | undefined;
|
|
78
|
-
errorContrast?: import("../lib/util/color.js").RgbColor | undefined;
|
|
79
|
-
errorHue?: number | undefined;
|
|
80
55
|
info?: import("../lib/util/color.js").RgbColor | undefined;
|
|
81
|
-
infoContrast?: import("../lib/util/color.js").RgbColor | undefined;
|
|
82
|
-
infoHue?: number | undefined;
|
|
83
56
|
primary?: import("../lib/util/color.js").RgbColor | undefined;
|
|
84
|
-
primaryContrast?: import("../lib/util/color.js").RgbColor | undefined;
|
|
85
|
-
primaryHue?: number | undefined;
|
|
86
57
|
success?: import("../lib/util/color.js").RgbColor | undefined;
|
|
87
|
-
successContrast?: import("../lib/util/color.js").RgbColor | undefined;
|
|
88
|
-
successHue?: number | undefined;
|
|
89
58
|
warning?: import("../lib/util/color.js").RgbColor | undefined;
|
|
90
|
-
|
|
91
|
-
|
|
59
|
+
} | undefined;
|
|
60
|
+
background?: {
|
|
61
|
+
light?: string | undefined;
|
|
62
|
+
dark?: string | undefined;
|
|
92
63
|
} | undefined;
|
|
93
64
|
links?: {
|
|
94
65
|
title: string | Record<string, string | undefined>;
|
|
@@ -99,24 +70,15 @@ export declare const customizationSchema: z.ZodObject<{
|
|
|
99
70
|
name?: string | undefined;
|
|
100
71
|
logo?: string | undefined;
|
|
101
72
|
colors?: {
|
|
102
|
-
light?: string | undefined;
|
|
103
|
-
dark?: string | undefined;
|
|
104
|
-
contrastSaturation?: number | undefined;
|
|
105
73
|
error?: string | undefined;
|
|
106
|
-
errorContrast?: string | undefined;
|
|
107
|
-
errorHue?: number | undefined;
|
|
108
74
|
info?: string | undefined;
|
|
109
|
-
infoContrast?: string | undefined;
|
|
110
|
-
infoHue?: number | undefined;
|
|
111
75
|
primary?: string | undefined;
|
|
112
|
-
primaryContrast?: string | undefined;
|
|
113
|
-
primaryHue?: number | undefined;
|
|
114
76
|
success?: string | undefined;
|
|
115
|
-
successContrast?: string | undefined;
|
|
116
|
-
successHue?: number | undefined;
|
|
117
77
|
warning?: string | undefined;
|
|
118
|
-
|
|
119
|
-
|
|
78
|
+
} | undefined;
|
|
79
|
+
background?: {
|
|
80
|
+
light?: string | undefined;
|
|
81
|
+
dark?: string | undefined;
|
|
120
82
|
} | undefined;
|
|
121
83
|
links?: {
|
|
122
84
|
title: string | Record<string, string | undefined>;
|
|
@@ -157,24 +119,15 @@ export declare const customizationSchema: z.ZodObject<{
|
|
|
157
119
|
name?: string | undefined;
|
|
158
120
|
logo?: string | undefined;
|
|
159
121
|
colors?: {
|
|
160
|
-
light?: import("../lib/util/color.js").RgbColor | undefined;
|
|
161
|
-
dark?: import("../lib/util/color.js").RgbColor | undefined;
|
|
162
|
-
contrastSaturation?: number | undefined;
|
|
163
122
|
error?: import("../lib/util/color.js").RgbColor | undefined;
|
|
164
|
-
errorContrast?: import("../lib/util/color.js").RgbColor | undefined;
|
|
165
|
-
errorHue?: number | undefined;
|
|
166
123
|
info?: import("../lib/util/color.js").RgbColor | undefined;
|
|
167
|
-
infoContrast?: import("../lib/util/color.js").RgbColor | undefined;
|
|
168
|
-
infoHue?: number | undefined;
|
|
169
124
|
primary?: import("../lib/util/color.js").RgbColor | undefined;
|
|
170
|
-
primaryContrast?: import("../lib/util/color.js").RgbColor | undefined;
|
|
171
|
-
primaryHue?: number | undefined;
|
|
172
125
|
success?: import("../lib/util/color.js").RgbColor | undefined;
|
|
173
|
-
successContrast?: import("../lib/util/color.js").RgbColor | undefined;
|
|
174
|
-
successHue?: number | undefined;
|
|
175
126
|
warning?: import("../lib/util/color.js").RgbColor | undefined;
|
|
176
|
-
|
|
177
|
-
|
|
127
|
+
} | undefined;
|
|
128
|
+
background?: {
|
|
129
|
+
light?: string | undefined;
|
|
130
|
+
dark?: string | undefined;
|
|
178
131
|
} | undefined;
|
|
179
132
|
links?: {
|
|
180
133
|
title: string | Record<string, string | undefined>;
|
|
@@ -196,24 +149,15 @@ export declare const customizationSchema: z.ZodObject<{
|
|
|
196
149
|
name?: string | undefined;
|
|
197
150
|
logo?: string | undefined;
|
|
198
151
|
colors?: {
|
|
199
|
-
light?: string | undefined;
|
|
200
|
-
dark?: string | undefined;
|
|
201
|
-
contrastSaturation?: number | undefined;
|
|
202
152
|
error?: string | undefined;
|
|
203
|
-
errorContrast?: string | undefined;
|
|
204
|
-
errorHue?: number | undefined;
|
|
205
153
|
info?: string | undefined;
|
|
206
|
-
infoContrast?: string | undefined;
|
|
207
|
-
infoHue?: number | undefined;
|
|
208
154
|
primary?: string | undefined;
|
|
209
|
-
primaryContrast?: string | undefined;
|
|
210
|
-
primaryHue?: number | undefined;
|
|
211
155
|
success?: string | undefined;
|
|
212
|
-
successContrast?: string | undefined;
|
|
213
|
-
successHue?: number | undefined;
|
|
214
156
|
warning?: string | undefined;
|
|
215
|
-
|
|
216
|
-
|
|
157
|
+
} | undefined;
|
|
158
|
+
background?: {
|
|
159
|
+
light?: string | undefined;
|
|
160
|
+
dark?: string | undefined;
|
|
217
161
|
} | undefined;
|
|
218
162
|
links?: {
|
|
219
163
|
title: string | Record<string, string | undefined>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"customization.d.ts","sourceRoot":"","sources":["../../src/customization/customization.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAIvB,eAAO,MAAM,mBAAmB;IAC9B;;;OAGG;;IAEH;;OAEG
|
|
1
|
+
{"version":3,"file":"customization.d.ts","sourceRoot":"","sources":["../../src/customization/customization.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAIvB,eAAO,MAAM,mBAAmB;IAC9B;;;OAGG;;IAEH;;OAEG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAEH;;OAEG;;IAEH;;OAEG;;IAEH;;OAEG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAEH,CAAA;AACF,MAAM,MAAM,mBAAmB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAA;AACrE,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAA"}
|
package/dist/lib/util/color.d.ts
CHANGED
|
@@ -31,5 +31,4 @@ export declare function parseRgbaColor(v: string): RgbaColor;
|
|
|
31
31
|
export declare function pickContrastColor(ref: RgbColor, a: RgbColor, b: RgbColor): RgbColor;
|
|
32
32
|
export declare function hslToRgb({ h, s, l }: HslColor): RgbColor;
|
|
33
33
|
export declare function hslToRgb({ h, s, l, a }: HslaColor): RgbaColor;
|
|
34
|
-
export declare function extractHue(input: RgbColor): number;
|
|
35
34
|
//# sourceMappingURL=color.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"color.d.ts","sourceRoot":"","sources":["../../../src/lib/util/color.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,QAAQ,GAAG;IAAE,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAA;CAAE,CAAA;AAC1D,MAAM,MAAM,QAAQ,GAAG;IAAE,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAA;CAAE,CAAA;AAC1D,MAAM,MAAM,SAAS,GAAG;IAAE,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAA;CAAE,CAAA;AACtE,MAAM,MAAM,SAAS,GAAG;IAAE,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MA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MAAM,MAAM,SAAS,GAAG;IAAE,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAA;CAAE,CAAA;AAEtE,MAAM,MAAM,KAAK,GAAG,QAAQ,GAAG,QAAQ,GAAG,SAAS,GAAG,SAAS,CAAA;AAE/D,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,QAAQ,GAAG,SAAS,CAe9D;AAED,wBAAgB,aAAa,CAAC,CAAC,EAAE,MAAM,GAAG,QAAQ,GAAG,SAAS,CAuB7D;AAED,wBAAgB,aAAa,CAAC,CAAC,EAAE,MAAM,GAAG,QAAQ,CAQjD;AAED,wBAAgB,cAAc,CAAC,CAAC,EAAE,MAAM,GAAG,SAAS,CAWnD;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,QAAQ,EAAE,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,QAAQ,YAExE;AAED,wBAAgB,QAAQ,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,QAAQ,GAAG,QAAQ,CAAA;AACzD,wBAAgB,QAAQ,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,SAAS,GAAG,SAAS,CAAA"}
|
package/dist/lib/util/color.js
CHANGED
|
@@ -108,32 +108,4 @@ function computeContrastRatio(a, b) {
|
|
|
108
108
|
const [lighter, darker] = aLum > bLum ? [aLum, bLum] : [bLum, aLum];
|
|
109
109
|
return (lighter + 0.05) / (darker + 0.05);
|
|
110
110
|
}
|
|
111
|
-
export function extractHue(input) {
|
|
112
|
-
const r = input.r / 255;
|
|
113
|
-
const g = input.g / 255;
|
|
114
|
-
const b = input.b / 255;
|
|
115
|
-
const max = Math.max(r, g, b);
|
|
116
|
-
const min = Math.min(r, g, b);
|
|
117
|
-
const chroma = max - min;
|
|
118
|
-
switch (max) {
|
|
119
|
-
case min:
|
|
120
|
-
return 0; // Achromatic
|
|
121
|
-
case r: {
|
|
122
|
-
const segment = (g - b) / chroma;
|
|
123
|
-
const shift = segment < 0 ? 360 / 60 : 0 / 60;
|
|
124
|
-
return 60 * (segment + shift);
|
|
125
|
-
}
|
|
126
|
-
case g: {
|
|
127
|
-
const segment = (b - r) / chroma;
|
|
128
|
-
const shift = 120 / 60;
|
|
129
|
-
return 60 * (segment + shift);
|
|
130
|
-
}
|
|
131
|
-
// "default" needed for type safety. In practice, should be same as "case b:"
|
|
132
|
-
default: {
|
|
133
|
-
const segment = (r - g) / chroma;
|
|
134
|
-
const shift = 240 / 60;
|
|
135
|
-
return 60 * (segment + shift);
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
111
|
//# sourceMappingURL=color.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"color.js","sourceRoot":"","sources":["../../../src/lib/util/color.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AASnD,MAAM,UAAU,UAAU,CAAC,KAAa;IACtC,IAAI,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;QAC1B,OAAO,aAAa,CAAC,KAAK,CAAC,CAAA;IAC7B,CAAC;IAED,IAAI,KAAK,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC;QAC9B,OAAO,cAAc,CAAC,KAAK,CAAC,CAAA;IAC9B,CAAC;IAED,IAAI,KAAK,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC;QAC7B,OAAO,aAAa,CAAC,KAAK,CAAC,CAAA;IAC7B,CAAC;IAED,qEAAqE;IACrE,MAAM,IAAI,SAAS,CAAC,wBAAwB,KAAK,EAAE,CAAC,CAAA;AACtD,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,CAAS;IACrC,wEAAwE;IACxE,IAAI,CAAC,eAAe,CAAC,IA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AM,CAAC,GAAG,KAAK,CAAC,CAAC,GAAG,GAAG,CAAA;IAEvB,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAA;IAC7B,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAA;IAE7B,MAAM,MAAM,GAAG,GAAG,GAAG,GAAG,CAAA;IAExB,QAAQ,GAAG,EAAE,CAAC;QACZ,KAAK,GAAG;YACN,OAAO,CAAC,CAAA,CAAC,aAAa;QACxB,KAAK,CAAC,EAAE,CAAC;YACP,MAAM,OAAO,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,MAAM,CAAA;YAChC,MAAM,KAAK,GAAG,OAAO,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC,GAAG,EAAE,CAAA;YAC7C,OAAO,EAAE,GAAG,CAAC,OAAO,GAAG,KAAK,CAAC,CAAA;QAC/B,CAAC;QACD,KAAK,CAAC,EAAE,CAAC;YACP,MAAM,OAAO,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,MAAM,CAAA;YAChC,MAAM,KAAK,GAAG,GAAG,GAAG,EAAE,CAAA;YACtB,OAAO,EAAE,GAAG,CAAC,OAAO,GAAG,KAAK,CAAC,CAAA;QAC/B,CAAC;QACD,6EAA6E;QAC7E,SAAS,CAAC;YACR,MAAM,OAAO,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,MAAM,CAAA;YAChC,MAAM,KAAK,GAAG,GAAG,GAAG,EAAE,CAAA;YACtB,OAAO,EAAE,GAAG,CAAC,OAAO,GAAG,KAAK,CAAC,CAAA;QAC/B,CAAC;IACH,CAAC;AACH,CAAC","sourcesContent":["import { parseUi8Dec, parseUi8Hex } from './ui8.js'\n\nexport type RgbColor = { r: number; g: number; b: number }\nexport type HslColor = { h: number; s: number; l: number }\nexport type RgbaColor = { r: number; g: number; b: number; a: number }\nexport type HslaColor = { h: number; s: number; l: number; a: number }\n\nexport type Color = RgbColor | HslColor | RgbaColor | HslaColor\n\nexport function parseColor(color: string): RgbColor | RgbaColor {\n if (color.startsWith('#')) {\n return parseHexColor(color)\n }\n\n if (color.startsWith('rgba(')) {\n return parseRgbaColor(color)\n }\n\n if (color.startsWith('rgb(')) {\n return parseRgbColor(color)\n }\n\n // Should never happen (as long as the input is a validated WebColor)\n throw new TypeError(`Invalid color value: ${color}`)\n}\n\nexport function parseHexColor(v: string): RgbColor | RgbaColor {\n // parseInt('az', 16) does not return NaN so we need to check the format\n if (!/^#[0-9a-f]+$/i.test(v)) {\n throw new TypeError(`Invalid hex color value: ${v}`)\n }\n\n if (v.length === 4 || v.length === 5) {\n const r = parseUi8Hex(v[1].repeat(2))\n const g = parseUi8Hex(v[2].repeat(2))\n const b = parseUi8Hex(v[3].repeat(2))\n const a = v.length > 4 ? parseUi8Hex(v[4].repeat(2)) : undefined\n return a == null ? { r, g, b } : { r, g, b, a }\n }\n\n if (v.length === 7 || v.length === 9) {\n const r = parseUi8Hex(v.slice(1, 3))\n const g = parseUi8Hex(v.slice(3, 5))\n const b = parseUi8Hex(v.slice(5, 7))\n const a = v.length > 8 ? parseUi8Hex(v.slice(7, 9)) : undefined\n return a == null ? { r, g, b } : { r, g, b, a }\n }\n\n throw new TypeError(`Invalid hex color value: ${v}`)\n}\n\nexport function parseRgbColor(v: string): RgbColor {\n const matches = v.match(/^\\s*rgb\\(\\s*(\\d+)\\s*,\\s*(\\d+)\\s*,\\s*(\\d+)\\s*\\)\\s*$/)\n if (!matches) throw new TypeError(`Invalid rgb color value: ${v}`)\n\n const r = parseUi8Dec(matches[1])\n const g = parseUi8Dec(matches[2])\n const b = parseUi8Dec(matches[3])\n return { r, g, b }\n}\n\nexport function parseRgbaColor(v: string): RgbaColor {\n const matches = v.match(\n /^\\s*rgba\\(\\s*(\\d+)\\s*,\\s*(\\d+)\\s*,\\s*(\\d+)\\s*,\\s*(\\d+)\\s*\\)\\s*$/,\n )\n if (!matches) throw new TypeError(`Invalid rgba color value: ${v}`)\n\n const r = parseUi8Dec(matches[1])\n const g = parseUi8Dec(matches[2])\n const b = parseUi8Dec(matches[3])\n const a = parseUi8Dec(matches[4])\n return { r, g, b, a }\n}\n\n/**\n * Return the color that has the best contrast with the reference color.\n */\nexport function pickContrastColor(ref: RgbColor, a: RgbColor, b: RgbColor) {\n return computeContrastRatio(ref, a) > computeContrastRatio(ref, b) ? a : b\n}\n\nexport function hslToRgb({ h, s, l }: HslColor): RgbColor\nexport function hslToRgb({ h, s, l, a }: HslaColor): RgbaColor\nexport function hslToRgb(input: HslaColor | HslColor): RgbColor | RgbaColor {\n const { h, s, l } = input\n\n // Achromatic (gray)\n if (s === 0) {\n const gray = Math.round(l * 255)\n return 'a' in input\n ? { r: gray, g: gray, b: gray, a: input.a }\n : { r: gray, g: gray, b: gray }\n }\n\n const hueToRgb = (p: number, q: number, t: number): number => {\n if (t < 0) t += 1\n if (t > 1) t -= 1\n if (t < 1 / 6) return p + (q - p) * 6 * t\n if (t < 1 / 2) return q\n if (t < 2 / 3) return p + (q - p) * (2 / 3 - t) * 6\n return p\n }\n\n const q = l < 0.5 ? l * (1 + s) : l + s - l * s\n const p = 2 * l - q\n const hNorm = h / 360\n\n const r = Math.round(hueToRgb(p, q, hNorm + 1 / 3) * 255)\n const g = Math.round(hueToRgb(p, q, hNorm) * 255)\n const b = Math.round(hueToRgb(p, q, hNorm - 1 / 3) * 255)\n\n return 'a' in input ? { r, g, b, a: input.a } : { r, g, b }\n}\n\n/**\n * @see {@link https://www.w3.org/TR/2008/REC-WCAG20-20081211/#relativeluminancedef}\n */\nfunction relativeLuminance(color: HslColor | RgbColor) {\n const { r, g, b } = 'h' in color ? hslToRgb(color) : color\n return rgbLum(r) * 0.2126 + rgbLum(g) * 0.7152 + rgbLum(b) * 0.0722\n}\n\nfunction rgbLum(value) {\n const rgb = value / 255\n return rgb < 0.03928 ? rgb / 12.92 : Math.pow((rgb + 0.055) / 1.055, 2.4)\n}\n\n/**\n * @see {@link https://www.w3.org/TR/2008/REC-WCAG20-20081211/#contrast-ratiodef}\n */\nfunction computeContrastRatio(a: RgbColor, b: RgbColor) {\n const aLum = relativeLuminance(a)\n const bLum = relativeLuminance(b)\n const [lighter, darker] = aLum > bLum ? [aLum, bLum] : [bLum, aLum]\n return (lighter + 0.05) / (darker + 0.05)\n}\n\nexport function extractHue(input: RgbColor): number {\n const r = input.r / 255\n const g = input.g / 255\n const b = input.b / 255\n\n const max = Math.max(r, g, b)\n const min = Math.min(r, g, b)\n\n const chroma = max - min\n\n switch (max) {\n case min:\n return 0 // Achromatic\n case r: {\n const segment = (g - b) / chroma\n const shift = segment < 0 ? 360 / 60 : 0 / 60\n return 60 * (segment + shift)\n }\n case g: {\n const segment = (b - r) / chroma\n const shift = 120 / 60\n return 60 * (segment + shift)\n }\n // \"default\" needed for type safety. In practice, should be same as \"case b:\"\n default: {\n const segment = (r - g) / chroma\n const shift = 240 / 60\n return 60 * (segment + shift)\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"color.js","sourceRoot":"","sources":["../../../src/lib/util/color.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AASnD,MAAM,UAAU,UAAU,CAAC,KAAa;IACtC,IAAI,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;QAC1B,OAAO,aAAa,CAAC,KAAK,CAAC,CAAA;IAC7B,CAAC;IAED,IAAI,KAAK,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC;QAC9B,OAAO,cAAc,CAAC,KAAK,CAAC,CAAA;IAC9B,CAAC;IAED,IAAI,KAAK,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC;QAC7B,OAAO,aAAa,CAAC,KAAK,CAAC,CAAA;IAC7B,CAAC;IAED,qEAAqE;IACrE,MA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i8Dec, parseUi8Hex } from './ui8.js'\n\nexport type RgbColor = { r: number; g: number; b: number }\nexport type HslColor = { h: number; s: number; l: number }\nexport type RgbaColor = { r: number; g: number; b: number; a: number }\nexport type HslaColor = { h: number; s: number; l: number; a: number }\n\nexport type Color = RgbColor | HslColor | RgbaColor | HslaColor\n\nexport function parseColor(color: string): RgbColor | RgbaColor {\n if (color.startsWith('#')) {\n return parseHexColor(color)\n }\n\n if (color.startsWith('rgba(')) {\n return parseRgbaColor(color)\n }\n\n if (color.startsWith('rgb(')) {\n return parseRgbColor(color)\n }\n\n // Should never happen (as long as the input is a validated WebColor)\n throw new TypeError(`Invalid color value: ${color}`)\n}\n\nexport function parseHexColor(v: string): RgbColor | RgbaColor {\n // parseInt('az', 16) does not return NaN so we need to check the format\n if (!/^#[0-9a-f]+$/i.test(v)) {\n throw new TypeError(`Invalid hex color value: ${v}`)\n }\n\n if (v.length === 4 || v.length === 5) {\n const r = parseUi8Hex(v[1].repeat(2))\n const g = parseUi8Hex(v[2].repeat(2))\n const b = parseUi8Hex(v[3].repeat(2))\n const a = v.length > 4 ? parseUi8Hex(v[4].repeat(2)) : undefined\n return a == null ? { r, g, b } : { r, g, b, a }\n }\n\n if (v.length === 7 || v.length === 9) {\n const r = parseUi8Hex(v.slice(1, 3))\n const g = parseUi8Hex(v.slice(3, 5))\n const b = parseUi8Hex(v.slice(5, 7))\n const a = v.length > 8 ? parseUi8Hex(v.slice(7, 9)) : undefined\n return a == null ? { r, g, b } : { r, g, b, a }\n }\n\n throw new TypeError(`Invalid hex color value: ${v}`)\n}\n\nexport function parseRgbColor(v: string): RgbColor {\n const matches = v.match(/^\\s*rgb\\(\\s*(\\d+)\\s*,\\s*(\\d+)\\s*,\\s*(\\d+)\\s*\\)\\s*$/)\n if (!matches) throw new TypeError(`Invalid rgb color value: ${v}`)\n\n const r = parseUi8Dec(matches[1])\n const g = parseUi8Dec(matches[2])\n const b = parseUi8Dec(matches[3])\n return { r, g, b }\n}\n\nexport function parseRgbaColor(v: string): RgbaColor {\n const matches = v.match(\n /^\\s*rgba\\(\\s*(\\d+)\\s*,\\s*(\\d+)\\s*,\\s*(\\d+)\\s*,\\s*(\\d+)\\s*\\)\\s*$/,\n )\n if (!matches) throw new TypeError(`Invalid rgba color value: ${v}`)\n\n const r = parseUi8Dec(matches[1])\n const g = parseUi8Dec(matches[2])\n const b = parseUi8Dec(matches[3])\n const a = parseUi8Dec(matches[4])\n return { r, g, b, a }\n}\n\n/**\n * Return the color that has the best contrast with the reference color.\n */\nexport function pickContrastColor(ref: RgbColor, a: RgbColor, b: RgbColor) {\n return computeContrastRatio(ref, a) > computeContrastRatio(ref, b) ? a : b\n}\n\nexport function hslToRgb({ h, s, l }: HslColor): RgbColor\nexport function hslToRgb({ h, s, l, a }: HslaColor): RgbaColor\nexport function hslToRgb(input: HslaColor | HslColor): RgbColor | RgbaColor {\n const { h, s, l } = input\n\n // Achromatic (gray)\n if (s === 0) {\n const gray = Math.round(l * 255)\n return 'a' in input\n ? { r: gray, g: gray, b: gray, a: input.a }\n : { r: gray, g: gray, b: gray }\n }\n\n const hueToRgb = (p: number, q: number, t: number): number => {\n if (t < 0) t += 1\n if (t > 1) t -= 1\n if (t < 1 / 6) return p + (q - p) * 6 * t\n if (t < 1 / 2) return q\n if (t < 2 / 3) return p + (q - p) * (2 / 3 - t) * 6\n return p\n }\n\n const q = l < 0.5 ? l * (1 + s) : l + s - l * s\n const p = 2 * l - q\n const hNorm = h / 360\n\n const r = Math.round(hueToRgb(p, q, hNorm + 1 / 3) * 255)\n const g = Math.round(hueToRgb(p, q, hNorm) * 255)\n const b = Math.round(hueToRgb(p, q, hNorm - 1 / 3) * 255)\n\n return 'a' in input ? { r, g, b, a: input.a } : { r, g, b }\n}\n\n/**\n * @see {@link https://www.w3.org/TR/2008/REC-WCAG20-20081211/#relativeluminancedef}\n */\nfunction relativeLuminance(color: HslColor | RgbColor) {\n const { r, g, b } = 'h' in color ? hslToRgb(color) : color\n return rgbLum(r) * 0.2126 + rgbLum(g) * 0.7152 + rgbLum(b) * 0.0722\n}\n\nfunction rgbLum(value) {\n const rgb = value / 255\n return rgb < 0.03928 ? rgb / 12.92 : Math.pow((rgb + 0.055) / 1.055, 2.4)\n}\n\n/**\n * @see {@link https://www.w3.org/TR/2008/REC-WCAG20-20081211/#contrast-ratiodef}\n */\nfunction computeContrastRatio(a: RgbColor, b: RgbColor) {\n const aLum = relativeLuminance(a)\n const bLum = relativeLuminance(b)\n const [lighter, darker] = aLum > bLum ? [aLum, bLum] : [bLum, aLum]\n return (lighter + 0.05) / (darker + 0.05)\n}\n"]}
|
package/dist/oauth-hooks.d.ts
CHANGED
|
@@ -29,7 +29,7 @@ export type OAuthHooks = {
|
|
|
29
29
|
*/
|
|
30
30
|
getClientInfo?: (clientId: ClientId, data: {
|
|
31
31
|
metadata: OAuthClientMetadata;
|
|
32
|
-
jwks
|
|
32
|
+
jwks: Jwks | undefined;
|
|
33
33
|
}) => Awaitable<undefined | Partial<ClientInfo>>;
|
|
34
34
|
/**
|
|
35
35
|
* This hook is called when a user requests an email change, before the email
|
|
@@ -218,6 +218,7 @@ export type OAuthHooks = {
|
|
|
218
218
|
input: SignUpInput;
|
|
219
219
|
deviceId: DeviceId;
|
|
220
220
|
deviceMetadata: RequestMetadata;
|
|
221
|
+
clientId: ClientId | undefined;
|
|
221
222
|
}) => Awaitable<void>;
|
|
222
223
|
/**
|
|
223
224
|
* This hook is called when a user attempts to sign up, after the hcaptcha
|
|
@@ -280,6 +281,7 @@ export type OAuthHooks = {
|
|
|
280
281
|
account: Account;
|
|
281
282
|
deviceId: DeviceId;
|
|
282
283
|
deviceMetadata: RequestMetadata;
|
|
284
|
+
clientId: ClientId | undefined;
|
|
283
285
|
}) => Awaitable<void>;
|
|
284
286
|
/**
|
|
285
287
|
* `clientId` is populated when the sign-in is submitted in the context of
|
|
@@ -291,7 +293,7 @@ export type OAuthHooks = {
|
|
|
291
293
|
data: SignInData;
|
|
292
294
|
deviceId: DeviceId;
|
|
293
295
|
deviceMetadata: RequestMetadata;
|
|
294
|
-
clientId
|
|
296
|
+
clientId: ClientId | undefined;
|
|
295
297
|
}) => Awaitable<void>;
|
|
296
298
|
/**
|
|
297
299
|
* This hook is called when a user successfully signs in.
|
|
@@ -306,7 +308,7 @@ export type OAuthHooks = {
|
|
|
306
308
|
account: Account;
|
|
307
309
|
deviceId: DeviceId;
|
|
308
310
|
deviceMetadata: RequestMetadata;
|
|
309
|
-
clientId
|
|
311
|
+
clientId: ClientId | undefined;
|
|
310
312
|
}) => Awaitable<void>;
|
|
311
313
|
/**
|
|
312
314
|
* This hook is called when a sign-in attempt is rejected by the account
|
|
@@ -332,7 +334,7 @@ export type OAuthHooks = {
|
|
|
332
334
|
did: Did | null;
|
|
333
335
|
deviceId: DeviceId;
|
|
334
336
|
deviceMetadata: RequestMetadata;
|
|
335
|
-
clientId
|
|
337
|
+
clientId: ClientId | undefined;
|
|
336
338
|
}) => Awaitable<void>;
|
|
337
339
|
/**
|
|
338
340
|
* Allows validating an authorization request (typically the requested scopes)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"oauth-hooks.d.ts","sourceRoot":"","sources":["../src/oauth-hooks.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,cAAc,CAAA;AACvC,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,cAAc,CAAA;AACxC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,6BAA6B,CAAA;AAC1D,OAAO,KAAK,EACV,gBAAgB,EAChB,yBAAyB,EACzB,mCAAmC,EACnC,mBAAmB,EACnB,kBAAkB,EAClB,cAAc,EACf,MAAM,sBAAsB,CAAA;AAC7B,OAAO,KAAK,EACV,yBAAyB,EACzB,yBAAyB,EACzB,yBAAyB,EACzB,UAAU,EACV,uBAAuB,EACvB,uBAAuB,EACvB,gBAAgB,EAChB,uBAAuB,EACvB,uBAAuB,EACxB,MAAM,4BAA4B,CAAA;AACnC,O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,CAAA;KAChD,KAAK,SAAS,CAAC,IAAI,CAAC,CAAA;IAErB;;;;OAIG;IACH,gBAAgB,CAAC,EAAE,CAAC,IAAI,EAAE;QACxB,MAAM,EAAE,MAAM,CAAA;QACd,UAAU,EAAE,UAAU,CAAA;QACtB,cAAc,EAAE,eAAe,CAAA;QAC/B,OAAO,EAAE,OAAO,CAAA;QAChB,UAAU,EAAE,mCAAmC,CAAA;KAChD,KAAK,SAAS,CAAC,IAAI,CAAC,CAAA;CACtB,CAAA"}
|
package/dist/oauth-hooks.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"oauth-hooks.js","sourceRoot":"","sources":["../src/oauth-hooks.ts"],"names":[],"mappings":"","sourcesContent":["import type { Did } from '@atproto/did'\nimport type { Jwks } from '@atproto/jwk'\nimport type { Account } from '@atproto/oauth-provider-api'\nimport type {\n OAuthAccessToken,\n OAuthAuthorizationDetails,\n OAuthAuthorizationRequestParameters,\n OAuthClientMetadata,\n OAuthTokenResponse,\n OAuthTokenType,\n} from '@atproto/oauth-types'\nimport type {\n DeleteAccountConfirmInput,\n ResetPasswordConfirmInput,\n ResetPasswordRequestInput,\n SignUpData,\n UpdateEmailConfirmInput,\n UpdateEmailRequestInput,\n UpdateHandleData,\n VerifyEmailConfirmInput,\n VerifyEmailRequestInput,\n} from './account/account-store.js'\nimport type { SignInData } from './account/sign-in-data.js'\nimport type { SignUpInput } from './account/sign-up-input.js'\nimport type { ClientAuth } from './client/client-auth.js'\nimport type { ClientId } from './client/client-id.js'\nimport type { ClientInfo } from './client/client-info.js'\nimport type { Client } from './client/client.js'\nimport type { DeviceId } from './device/device-id.js'\nimport type { DpopProof } from './dpop/dpop-proof.js'\nimport type { InvalidRequestError } from './errors/invalid-request-error.js'\nimport type {\n HcaptchaClientTokens,\n HcaptchaConfig,\n HcaptchaVerifyResult,\n} from './lib/hcaptcha.js'\nimport type { RequestMetadata } from './lib/http/request.js'\nimport type { Awaitable, OmitKey } from './lib/util/type.js'\nimport type { RequestId } from './request/request-id.js'\nimport type { AccessTokenPayload } from './signer/access-token-payload.js'\nimport type { TokenClaims } from './token/token-claims.js'\n\n// Make sure all types needed to implement the OAuthHooks are exported\nexport type {\n AccessTokenPayload,\n Account,\n Awaitable,\n Client,\n ClientAuth,\n ClientId,\n ClientInfo,\n DeviceId,\n Did,\n DpopProof,\n HcaptchaClientTokens,\n HcaptchaConfig,\n HcaptchaVerifyResult,\n Jwks,\n OAuthAccessToken,\n OAuthAuthorizationDetails,\n OAuthAuthorizationRequestParameters,\n OAuthClientMetadata,\n OAuthTokenResponse,\n OAuthTokenType,\n RequestMetadata,\n ResetPasswordConfirmInput,\n ResetPasswordRequestInput,\n SignInData,\n SignUpData,\n SignUpInput,\n TokenClaims,\n UpdateHandleData,\n}\n\nexport type OAuthHooks = {\n /**\n * Use this to alter, override or validate the client metadata & jwks returned\n * by the client store.\n *\n * @throws {InvalidClientMetadataError} if the metadata is invalid\n * @see {@link InvalidClientMetadataError}\n */\n getClientInfo?: (\n clientId: ClientId,\n data: { metadata: OAuthClientMetadata; jwks?: Jwks },\n ) => Awaitable<undefined | Partial<ClientInfo>>\n\n /**\n * This hook is called when a user requests an email change, before the email\n * change request is triggered on the account store. Only triggered with\n * authenticated sessions, so the `account` is always available.\n */\n onChangeEmailRequest?: (data: {\n input: UpdateEmailRequestInput\n deviceId: DeviceId\n deviceMetadata: RequestMetadata\n account: Account\n }) => Awaitable<void>\n\n /**\n * This hook is called after a user requests an email change, and the email\n * change request was successfully triggered on the account store.\n */\n onChangeEmailRequested?: (data: {\n input: UpdateEmailRequestInput\n deviceId: DeviceId\n deviceMetadata: RequestMetadata\n account: Account\n }) => Awaitable<void>\n\n /**\n * This hook is called when a user confirms an email change, before the email\n * change is actually confirmed on the account store. Only triggered with\n * authenticated sessions, so the `account` is always available.\n */\n onUpdateEmailConfirm?: (data: {\n input: UpdateEmailConfirmInput\n deviceId: DeviceId\n deviceMetadata: RequestMetadata\n account: Account\n }) => Awaitable<void>\n\n /**\n * This hook is called after a user confirms an email change, and the email\n * change was successfully confirmed on the account store.\n */\n onUpdateEmailConfirmed?: (data: {\n input: UpdateEmailConfirmInput\n deviceId: DeviceId\n deviceMetadata: RequestMetadata\n account: Account\n prevAccount: Account\n }) => Awaitable<void>\n\n /**\n * This hook is called when a user requests an email verification, before the\n * verification request is triggered on the account store. Only triggered with\n * authenticated sessions, so the `account` is always available.\n */\n onVerifyEmailRequest?: (data: {\n input: VerifyEmailRequestInput\n deviceId: DeviceId\n deviceMetadata: RequestMetadata\n account: Account\n }) => Awaitable<void>\n\n /**\n * This hook is called after a user requests an email verification, and the\n * verification request was successfully triggered on the account store.\n */\n onVerifyEmailRequested?: (data: {\n input: VerifyEmailRequestInput\n deviceId: DeviceId\n deviceMetadata: RequestMetadata\n account: Account\n }) => Awaitable<void>\n\n /**\n * This hook is called when a user confirms an email verification, before the\n * verification is actually confirmed on the account store. Only triggered\n * with authenticated sessions, so the `account` is always available.\n */\n onVerifyEmailConfirm?: (data: {\n input: VerifyEmailConfirmInput\n deviceId: DeviceId\n deviceMetadata: RequestMetadata\n account: Account\n }) => Awaitable<void>\n\n /**\n * This hook is called after a user confirms an email verification, and the\n * verification was successfully confirmed on the account store.\n */\n onVerifyEmailConfirmed?: (data: {\n input: VerifyEmailConfirmInput\n deviceId: DeviceId\n deviceMetadata: RequestMetadata\n account: Account\n }) => Awaitable<void>\n\n /**\n * This hook is called when a user requests a handle change, before the change\n * is performed on the account store. Only triggered with authenticated\n * sessions, so the `account` is always available.\n */\n onUpdateHandle?: (data: {\n input: UpdateHandleData\n deviceId: DeviceId\n deviceMetadata: RequestMetadata\n account: Account\n }) => Awaitable<void>\n\n /**\n * This hook is called after a user successfully changed their handle on the\n * account store.\n */\n onUpdatedHandle?: (data: {\n input: UpdateHandleData\n deviceId: DeviceId\n deviceMetadata: RequestMetadata\n account: Account\n }) => Awaitable<void>\n\n /**\n * This hook is called when a user requests account deactivation, before the\n * account is deactivated on the account store.\n */\n onDeactivateAccount?: (data: {\n deviceId: DeviceId\n deviceMetadata: RequestMetadata\n account: Account\n }) => Awaitable<void>\n\n /**\n * This hook is called after a user successfully deactivated their account on\n * the account store.\n */\n onDeactivatedAccount?: (data: {\n deviceId: DeviceId\n deviceMetadata: RequestMetadata\n account: Account\n }) => Awaitable<void>\n\n /**\n * This hook is called when a user requests account reactivation, before the\n * account is reactivated on the account store.\n */\n onReactivateAccount?: (data: {\n deviceId: DeviceId\n deviceMetadata: RequestMetadata\n account: Account\n }) => Awaitable<void>\n\n /**\n * This hook is called after a user successfully reactivated their account on\n * the account store.\n */\n onReactivatedAccount?: (data: {\n deviceId: DeviceId\n deviceMetadata: RequestMetadata\n account: Account\n }) => Awaitable<void>\n\n /**\n * This hook is called when a user requests account deletion, before the\n * confirmation email is dispatched on the account store.\n */\n onDeleteAccountRequest?: (data: {\n deviceId: DeviceId\n deviceMetadata: RequestMetadata\n account: Account\n }) => Awaitable<void>\n\n /**\n * This hook is called after a user has requested account deletion and the\n * confirmation email has been dispatched.\n */\n onDeleteAccountRequested?: (data: {\n deviceId: DeviceId\n deviceMetadata: RequestMetadata\n account: Account\n }) => Awaitable<void>\n\n /**\n * This hook is called when a user confirms account deletion, before the\n * account is actually deleted on the account store.\n */\n onDeleteAccountConfirm?: (data: {\n deviceId: DeviceId\n deviceMetadata: RequestMetadata\n account: Account\n }) => Awaitable<void>\n\n /**\n * This hook is called after a user has successfully deleted their account\n * on the account store.\n */\n onDeleteAccountConfirmed?: (data: {\n deviceId: DeviceId\n deviceMetadata: RequestMetadata\n account: Account\n input: DeleteAccountConfirmInput\n }) => Awaitable<void>\n\n /**\n * This hook is called when a user attempts to sign up, after every validation\n * has passed (including hcaptcha).\n */\n onSignUpAttempt?: (data: {\n input: SignUpInput\n deviceId: DeviceId\n deviceMetadata: RequestMetadata\n }) => Awaitable<void>\n\n /**\n * This hook is called when a user attempts to sign up, after the hcaptcha\n * `/siteverify` request has been made (and before the result is validated).\n */\n onHcaptchaResult?: (data: {\n input: SignUpInput\n deviceId: DeviceId\n deviceMetadata: RequestMetadata\n tokens: HcaptchaClientTokens\n result: HcaptchaVerifyResult\n }) => Awaitable<void>\n\n /**\n * This hook is called when a user requests a password reset, before the\n * reset password request is triggered on the account store. Use this to\n * potentially cancel the password reset.\n */\n onResetPasswordRequest?: (data: {\n input: ResetPasswordRequestInput\n deviceId: DeviceId\n deviceMetadata: RequestMetadata\n }) => Awaitable<void>\n\n /**\n * This hook is called when a user requests a password reset, before the\n * reset password request is triggered on the account store. If not account\n * was found for the provided identifier, the `account` field will be `null`.\n */\n onResetPasswordRequested?: (data: {\n input: ResetPasswordRequestInput\n deviceId: DeviceId\n deviceMetadata: RequestMetadata\n account: Account | null\n }) => Awaitable<void>\n\n /**\n * This hook is called when a user confirms a password reset, before the\n * password is actually reset on the account store.\n */\n onResetPasswordConfirm?: (data: {\n input: ResetPasswordConfirmInput\n deviceId: DeviceId\n deviceMetadata: RequestMetadata\n }) => Awaitable<void>\n\n /**\n * This hook is called after a user confirms a password reset, and the\n * password was successfully reset on the account store.\n */\n onResetPasswordConfirmed?: (data: {\n input: ResetPasswordConfirmInput\n deviceId: DeviceId\n deviceMetadata: RequestMetadata\n account: Account\n }) => Awaitable<void>\n\n /**\n * This hook is called when a user successfully signs up.\n *\n * @throws {AccessDeniedError} to deny the sign-up\n */\n onSignedUp?: (data: {\n data: SignUpData\n account: Account\n deviceId: DeviceId\n deviceMetadata: RequestMetadata\n }) => Awaitable<void>\n\n /**\n * `clientId` is populated when the sign-in is submitted in the context of\n * an OAuth authorization request (i.e. the user is logging in to approve a\n * client); it is omitted for first-party sign-ins that happen outside any\n * authorization flow.\n */\n onSignInAttempt?: (data: {\n data: SignInData\n deviceId: DeviceId\n deviceMetadata: RequestMetadata\n clientId?: ClientId\n }) => Awaitable<void>\n\n /**\n * This hook is called when a user successfully signs in.\n *\n * `clientId` is populated when the sign-in is submitted in the context of\n * an OAuth authorization request; see {@link OAuthHooks.onSignInAttempt}.\n *\n * @throws {InvalidRequestError} when the sing-in should be denied\n */\n onSignedIn?: (data: {\n data: SignInData\n account: Account\n deviceId: DeviceId\n deviceMetadata: RequestMetadata\n clientId?: ClientId\n }) => Awaitable<void>\n\n /**\n * This hook is called when a sign-in attempt is rejected by the account\n * store due to invalid credentials (e.g. unknown identifier, wrong\n * password). It is *not* called for unexpected server errors, nor for flows\n * that require an additional authentication factor.\n *\n * `sub` is populated when the store throws an\n * {@link InvalidCredentialsError} that carries the matched subject\n * identifier (i.e. identifier known, credentials wrong). It is `null` when\n * the identifier was unknown or when the store threw a plain\n * {@link InvalidRequestError} without distinguishing the two cases.\n *\n * `clientId` is populated when the sign-in is submitted in the context of\n * an OAuth authorization request; see {@link OAuthHooks.onSignInAttempt}.\n *\n * Errors thrown from this hook are caught and ignored so that they do not\n * mask the original authentication failure.\n */\n onSignInFailed?: (data: {\n data: SignInData\n error: InvalidRequestError\n did: Did | null\n deviceId: DeviceId\n deviceMetadata: RequestMetadata\n clientId?: ClientId\n }) => Awaitable<void>\n\n /**\n * Allows validating an authorization request (typically the requested scopes)\n * before it is created. Note that the validity against the client metadata is\n * already enforced by the OAuth provider.\n *\n * @throws {AuthorizationError}\n */\n onAuthorizationRequest?: (data: {\n client: Client\n clientAuth: null | ClientAuth\n parameters: Readonly<OAuthAuthorizationRequestParameters>\n }) => Awaitable<void>\n\n /**\n * This hook is called when a client is authorized.\n *\n * @throws {AuthorizationError} to deny the authorization request and redirect\n * the user to the client with an OAuth error (other errors will result in an\n * internal server error being displayed to the user)\n *\n * @note We use `deviceMetadata` instead of `clientMetadata` to make it clear\n * that this metadata is from the user device, which might be different from\n * the client metadata (because the OAuth client could live in a backend).\n */\n onAuthorized?: (data: {\n client: Client\n account: Account\n parameters: OAuthAuthorizationRequestParameters\n deviceId: DeviceId\n deviceMetadata: RequestMetadata\n requestId: RequestId\n }) => Awaitable<void>\n\n /**\n * This hook is called whenever a token is about to be created. You can use\n * it to modify the token claims or perform additional validation.\n *\n * This hook should never throw an error.\n */\n onCreateToken?: (data: {\n client: Client\n account: Account\n parameters: OAuthAuthorizationRequestParameters\n claims: TokenClaims\n }) => Awaitable<void | OmitKey<AccessTokenPayload, 'iss'>>\n\n /**\n * This hook is called whenever a token was just decoded, and basic validation\n * was performed (signature, expiration, not-before).\n *\n * It can be used to modify the payload (e.g., to add custom claims), or to\n * perform additional validation.\n *\n * This hook is called when authenticating requests through the\n * `authenticateRequest()` method in `OAuthVerifier` and `OAuthProvider`.\n *\n * Any error thrown here will be propagated.\n */\n onDecodeToken?: (data: {\n tokenType: OAuthTokenType\n token: OAuthAccessToken\n payload: AccessTokenPayload\n dpopProof: null | DpopProof\n }) => Promise<AccessTokenPayload | void>\n\n /**\n * This hook is called when an authorized client exchanges an authorization\n * code for an access token.\n *\n * @throws {OAuthError} to cancel the token creation and revoke the session\n */\n onTokenCreated?: (data: {\n client: Client\n clientAuth: ClientAuth\n clientMetadata: RequestMetadata\n account: Account\n parameters: OAuthAuthorizationRequestParameters\n }) => Awaitable<void>\n\n /**\n * This hook is called when an authorized client refreshes an access token.\n *\n * @throws {OAuthError} to cancel the token refresh and revoke the session\n */\n onTokenRefreshed?: (data: {\n client: Client\n clientAuth: ClientAuth\n clientMetadata: RequestMetadata\n account: Account\n parameters: OAuthAuthorizationRequestParameters\n }) => Awaitable<void>\n}\n"]}
|
|
1
|
+
{"version":3,"file":"oauth-hooks.js","sourceRoot":"","sources":["../src/oauth-hooks.ts"],"names":[],"mappings":"","sourcesContent":["import type { Did } from '@atproto/did'\nimport type { Jwks } from '@atproto/jwk'\nimport type { Account } from '@atproto/oauth-provider-api'\nimport type {\n OAuthAccessToken,\n OAuthAuthorizationDetails,\n OAuthAuthorizationRequestParameters,\n OAuthClientMetadata,\n OAuthTokenResponse,\n OAuthTokenType,\n} from '@atproto/oauth-types'\nimport type {\n DeleteAccountConfirmInput,\n ResetPasswordConfirmInput,\n ResetPasswordRequestInput,\n SignUpData,\n UpdateEmailConfirmInput,\n UpdateEmailRequestInput,\n UpdateHandleData,\n VerifyEmailConfirmInput,\n VerifyEmailRequestInput,\n} from './account/account-store.js'\nimport type { SignInData } from './account/sign-in-data.js'\nimport type { SignUpInput } from './account/sign-up-input.js'\nimport type { ClientAuth } from './client/client-auth.js'\nimport type { ClientId } from './client/client-id.js'\nimport type { ClientInfo } from './client/client-info.js'\nimport type { Client } from './client/client.js'\nimport type { DeviceId } from './device/device-id.js'\nimport type { DpopProof } from './dpop/dpop-proof.js'\nimport type { InvalidRequestError } from './errors/invalid-request-error.js'\nimport type {\n HcaptchaClientTokens,\n HcaptchaConfig,\n HcaptchaVerifyResult,\n} from './lib/hcaptcha.js'\nimport type { RequestMetadata } from './lib/http/request.js'\nimport type { Awaitable, OmitKey } from './lib/util/type.js'\nimport type { RequestId } from './request/request-id.js'\nimport type { AccessTokenPayload } from './signer/access-token-payload.js'\nimport type { TokenClaims } from './token/token-claims.js'\n\n// Make sure all types needed to implement the OAuthHooks are exported\nexport type {\n AccessTokenPayload,\n Account,\n Awaitable,\n Client,\n ClientAuth,\n ClientId,\n ClientInfo,\n DeviceId,\n Did,\n DpopProof,\n HcaptchaClientTokens,\n HcaptchaConfig,\n HcaptchaVerifyResult,\n Jwks,\n OAuthAccessToken,\n OAuthAuthorizationDetails,\n OAuthAuthorizationRequestParameters,\n OAuthClientMetadata,\n OAuthTokenResponse,\n OAuthTokenType,\n RequestMetadata,\n ResetPasswordConfirmInput,\n ResetPasswordRequestInput,\n SignInData,\n SignUpData,\n SignUpInput,\n TokenClaims,\n UpdateHandleData,\n}\n\nexport type OAuthHooks = {\n /**\n * Use this to alter, override or validate the client metadata & jwks returned\n * by the client store.\n *\n * @throws {InvalidClientMetadataError} if the metadata is invalid\n * @see {@link InvalidClientMetadataError}\n */\n getClientInfo?: (\n clientId: ClientId,\n data: {\n metadata: OAuthClientMetadata\n jwks: Jwks | undefined\n },\n ) => Awaitable<undefined | Partial<ClientInfo>>\n\n /**\n * This hook is called when a user requests an email change, before the email\n * change request is triggered on the account store. Only triggered with\n * authenticated sessions, so the `account` is always available.\n */\n onChangeEmailRequest?: (data: {\n input: UpdateEmailRequestInput\n deviceId: DeviceId\n deviceMetadata: RequestMetadata\n account: Account\n }) => Awaitable<void>\n\n /**\n * This hook is called after a user requests an email change, and the email\n * change request was successfully triggered on the account store.\n */\n onChangeEmailRequested?: (data: {\n input: UpdateEmailRequestInput\n deviceId: DeviceId\n deviceMetadata: RequestMetadata\n account: Account\n }) => Awaitable<void>\n\n /**\n * This hook is called when a user confirms an email change, before the email\n * change is actually confirmed on the account store. Only triggered with\n * authenticated sessions, so the `account` is always available.\n */\n onUpdateEmailConfirm?: (data: {\n input: UpdateEmailConfirmInput\n deviceId: DeviceId\n deviceMetadata: RequestMetadata\n account: Account\n }) => Awaitable<void>\n\n /**\n * This hook is called after a user confirms an email change, and the email\n * change was successfully confirmed on the account store.\n */\n onUpdateEmailConfirmed?: (data: {\n input: UpdateEmailConfirmInput\n deviceId: DeviceId\n deviceMetadata: RequestMetadata\n account: Account\n prevAccount: Account\n }) => Awaitable<void>\n\n /**\n * This hook is called when a user requests an email verification, before the\n * verification request is triggered on the account store. Only triggered with\n * authenticated sessions, so the `account` is always available.\n */\n onVerifyEmailRequest?: (data: {\n input: VerifyEmailRequestInput\n deviceId: DeviceId\n deviceMetadata: RequestMetadata\n account: Account\n }) => Awaitable<void>\n\n /**\n * This hook is called after a user requests an email verification, and the\n * verification request was successfully triggered on the account store.\n */\n onVerifyEmailRequested?: (data: {\n input: VerifyEmailRequestInput\n deviceId: DeviceId\n deviceMetadata: RequestMetadata\n account: Account\n }) => Awaitable<void>\n\n /**\n * This hook is called when a user confirms an email verification, before the\n * verification is actually confirmed on the account store. Only triggered\n * with authenticated sessions, so the `account` is always available.\n */\n onVerifyEmailConfirm?: (data: {\n input: VerifyEmailConfirmInput\n deviceId: DeviceId\n deviceMetadata: RequestMetadata\n account: Account\n }) => Awaitable<void>\n\n /**\n * This hook is called after a user confirms an email verification, and the\n * verification was successfully confirmed on the account store.\n */\n onVerifyEmailConfirmed?: (data: {\n input: VerifyEmailConfirmInput\n deviceId: DeviceId\n deviceMetadata: RequestMetadata\n account: Account\n }) => Awaitable<void>\n\n /**\n * This hook is called when a user requests a handle change, before the change\n * is performed on the account store. Only triggered with authenticated\n * sessions, so the `account` is always available.\n */\n onUpdateHandle?: (data: {\n input: UpdateHandleData\n deviceId: DeviceId\n deviceMetadata: RequestMetadata\n account: Account\n }) => Awaitable<void>\n\n /**\n * This hook is called after a user successfully changed their handle on the\n * account store.\n */\n onUpdatedHandle?: (data: {\n input: UpdateHandleData\n deviceId: DeviceId\n deviceMetadata: RequestMetadata\n account: Account\n }) => Awaitable<void>\n\n /**\n * This hook is called when a user requests account deactivation, before the\n * account is deactivated on the account store.\n */\n onDeactivateAccount?: (data: {\n deviceId: DeviceId\n deviceMetadata: RequestMetadata\n account: Account\n }) => Awaitable<void>\n\n /**\n * This hook is called after a user successfully deactivated their account on\n * the account store.\n */\n onDeactivatedAccount?: (data: {\n deviceId: DeviceId\n deviceMetadata: RequestMetadata\n account: Account\n }) => Awaitable<void>\n\n /**\n * This hook is called when a user requests account reactivation, before the\n * account is reactivated on the account store.\n */\n onReactivateAccount?: (data: {\n deviceId: DeviceId\n deviceMetadata: RequestMetadata\n account: Account\n }) => Awaitable<void>\n\n /**\n * This hook is called after a user successfully reactivated their account on\n * the account store.\n */\n onReactivatedAccount?: (data: {\n deviceId: DeviceId\n deviceMetadata: RequestMetadata\n account: Account\n }) => Awaitable<void>\n\n /**\n * This hook is called when a user requests account deletion, before the\n * confirmation email is dispatched on the account store.\n */\n onDeleteAccountRequest?: (data: {\n deviceId: DeviceId\n deviceMetadata: RequestMetadata\n account: Account\n }) => Awaitable<void>\n\n /**\n * This hook is called after a user has requested account deletion and the\n * confirmation email has been dispatched.\n */\n onDeleteAccountRequested?: (data: {\n deviceId: DeviceId\n deviceMetadata: RequestMetadata\n account: Account\n }) => Awaitable<void>\n\n /**\n * This hook is called when a user confirms account deletion, before the\n * account is actually deleted on the account store.\n */\n onDeleteAccountConfirm?: (data: {\n deviceId: DeviceId\n deviceMetadata: RequestMetadata\n account: Account\n }) => Awaitable<void>\n\n /**\n * This hook is called after a user has successfully deleted their account\n * on the account store.\n */\n onDeleteAccountConfirmed?: (data: {\n deviceId: DeviceId\n deviceMetadata: RequestMetadata\n account: Account\n input: DeleteAccountConfirmInput\n }) => Awaitable<void>\n\n /**\n * This hook is called when a user attempts to sign up, after every validation\n * has passed (including hcaptcha).\n */\n onSignUpAttempt?: (data: {\n input: SignUpInput\n deviceId: DeviceId\n deviceMetadata: RequestMetadata\n clientId: ClientId | undefined\n }) => Awaitable<void>\n\n /**\n * This hook is called when a user attempts to sign up, after the hcaptcha\n * `/siteverify` request has been made (and before the result is validated).\n */\n onHcaptchaResult?: (data: {\n input: SignUpInput\n deviceId: DeviceId\n deviceMetadata: RequestMetadata\n tokens: HcaptchaClientTokens\n result: HcaptchaVerifyResult\n }) => Awaitable<void>\n\n /**\n * This hook is called when a user requests a password reset, before the\n * reset password request is triggered on the account store. Use this to\n * potentially cancel the password reset.\n */\n onResetPasswordRequest?: (data: {\n input: ResetPasswordRequestInput\n deviceId: DeviceId\n deviceMetadata: RequestMetadata\n }) => Awaitable<void>\n\n /**\n * This hook is called when a user requests a password reset, before the\n * reset password request is triggered on the account store. If not account\n * was found for the provided identifier, the `account` field will be `null`.\n */\n onResetPasswordRequested?: (data: {\n input: ResetPasswordRequestInput\n deviceId: DeviceId\n deviceMetadata: RequestMetadata\n account: Account | null\n }) => Awaitable<void>\n\n /**\n * This hook is called when a user confirms a password reset, before the\n * password is actually reset on the account store.\n */\n onResetPasswordConfirm?: (data: {\n input: ResetPasswordConfirmInput\n deviceId: DeviceId\n deviceMetadata: RequestMetadata\n }) => Awaitable<void>\n\n /**\n * This hook is called after a user confirms a password reset, and the\n * password was successfully reset on the account store.\n */\n onResetPasswordConfirmed?: (data: {\n input: ResetPasswordConfirmInput\n deviceId: DeviceId\n deviceMetadata: RequestMetadata\n account: Account\n }) => Awaitable<void>\n\n /**\n * This hook is called when a user successfully signs up.\n *\n * @throws {AccessDeniedError} to deny the sign-up\n */\n onSignedUp?: (data: {\n data: SignUpData\n account: Account\n deviceId: DeviceId\n deviceMetadata: RequestMetadata\n clientId: ClientId | undefined\n }) => Awaitable<void>\n\n /**\n * `clientId` is populated when the sign-in is submitted in the context of\n * an OAuth authorization request (i.e. the user is logging in to approve a\n * client); it is omitted for first-party sign-ins that happen outside any\n * authorization flow.\n */\n onSignInAttempt?: (data: {\n data: SignInData\n deviceId: DeviceId\n deviceMetadata: RequestMetadata\n clientId: ClientId | undefined\n }) => Awaitable<void>\n\n /**\n * This hook is called when a user successfully signs in.\n *\n * `clientId` is populated when the sign-in is submitted in the context of\n * an OAuth authorization request; see {@link OAuthHooks.onSignInAttempt}.\n *\n * @throws {InvalidRequestError} when the sing-in should be denied\n */\n onSignedIn?: (data: {\n data: SignInData\n account: Account\n deviceId: DeviceId\n deviceMetadata: RequestMetadata\n clientId: ClientId | undefined\n }) => Awaitable<void>\n\n /**\n * This hook is called when a sign-in attempt is rejected by the account\n * store due to invalid credentials (e.g. unknown identifier, wrong\n * password). It is *not* called for unexpected server errors, nor for flows\n * that require an additional authentication factor.\n *\n * `sub` is populated when the store throws an\n * {@link InvalidCredentialsError} that carries the matched subject\n * identifier (i.e. identifier known, credentials wrong). It is `null` when\n * the identifier was unknown or when the store threw a plain\n * {@link InvalidRequestError} without distinguishing the two cases.\n *\n * `clientId` is populated when the sign-in is submitted in the context of\n * an OAuth authorization request; see {@link OAuthHooks.onSignInAttempt}.\n *\n * Errors thrown from this hook are caught and ignored so that they do not\n * mask the original authentication failure.\n */\n onSignInFailed?: (data: {\n data: SignInData\n error: InvalidRequestError\n did: Did | null\n deviceId: DeviceId\n deviceMetadata: RequestMetadata\n clientId: ClientId | undefined\n }) => Awaitable<void>\n\n /**\n * Allows validating an authorization request (typically the requested scopes)\n * before it is created. Note that the validity against the client metadata is\n * already enforced by the OAuth provider.\n *\n * @throws {AuthorizationError}\n */\n onAuthorizationRequest?: (data: {\n client: Client\n clientAuth: null | ClientAuth\n parameters: Readonly<OAuthAuthorizationRequestParameters>\n }) => Awaitable<void>\n\n /**\n * This hook is called when a client is authorized.\n *\n * @throws {AuthorizationError} to deny the authorization request and redirect\n * the user to the client with an OAuth error (other errors will result in an\n * internal server error being displayed to the user)\n *\n * @note We use `deviceMetadata` instead of `clientMetadata` to make it clear\n * that this metadata is from the user device, which might be different from\n * the client metadata (because the OAuth client could live in a backend).\n */\n onAuthorized?: (data: {\n client: Client\n account: Account\n parameters: OAuthAuthorizationRequestParameters\n deviceId: DeviceId\n deviceMetadata: RequestMetadata\n requestId: RequestId\n }) => Awaitable<void>\n\n /**\n * This hook is called whenever a token is about to be created. You can use\n * it to modify the token claims or perform additional validation.\n *\n * This hook should never throw an error.\n */\n onCreateToken?: (data: {\n client: Client\n account: Account\n parameters: OAuthAuthorizationRequestParameters\n claims: TokenClaims\n }) => Awaitable<void | OmitKey<AccessTokenPayload, 'iss'>>\n\n /**\n * This hook is called whenever a token was just decoded, and basic validation\n * was performed (signature, expiration, not-before).\n *\n * It can be used to modify the payload (e.g., to add custom claims), or to\n * perform additional validation.\n *\n * This hook is called when authenticating requests through the\n * `authenticateRequest()` method in `OAuthVerifier` and `OAuthProvider`.\n *\n * Any error thrown here will be propagated.\n */\n onDecodeToken?: (data: {\n tokenType: OAuthTokenType\n token: OAuthAccessToken\n payload: AccessTokenPayload\n dpopProof: null | DpopProof\n }) => Promise<AccessTokenPayload | void>\n\n /**\n * This hook is called when an authorized client exchanges an authorization\n * code for an access token.\n *\n * @throws {OAuthError} to cancel the token creation and revoke the session\n */\n onTokenCreated?: (data: {\n client: Client\n clientAuth: ClientAuth\n clientMetadata: RequestMetadata\n account: Account\n parameters: OAuthAuthorizationRequestParameters\n }) => Awaitable<void>\n\n /**\n * This hook is called when an authorized client refreshes an access token.\n *\n * @throws {OAuthError} to cancel the token refresh and revoke the session\n */\n onTokenRefreshed?: (data: {\n client: Client\n clientAuth: ClientAuth\n clientMetadata: RequestMetadata\n account: Account\n parameters: OAuthAuthorizationRequestParameters\n }) => Awaitable<void>\n}\n"]}
|
|
@@ -59,7 +59,7 @@ export function sendWebAppFactory(page, customization, defaults = {}) {
|
|
|
59
59
|
__customizationData: customizationData,
|
|
60
60
|
});
|
|
61
61
|
return writeHtml(res, mergeDefaults(defaults, options, {
|
|
62
|
-
bodyAttrs: { class: 'text-
|
|
62
|
+
bodyAttrs: { class: 'text-foreground bg-background' },
|
|
63
63
|
csp: options?.csp ? mergeCsp(csp, options.csp) : csp,
|
|
64
64
|
coep: options?.coep ?? coep,
|
|
65
65
|
meta: [{ name: 'robots', content: 'noindex' }],
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"assets.js","sourceRoot":"","sources":["../../../src/router/assets/assets.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAE3C,OAAO,EAAE,qBAAqB,EAAE,MAAM,gDAAgD,CAAA;AACtF,OAAO,EAAE,sBAAsB,EAAE,MAAM,iDAAiD,CAAA;AAExF,OAAO,EAAkB,QAAQ,EAAE,MAAM,wBAAwB,CAAA;AACjE,OAAO,EAAE,oBAAoB,EAAE,MAAM,kCAAkC,CAAA;AACvE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAA;AAEvD,OAAO,EACL,yBAAyB,GAE1B,MAAM,oCAAoC,CAAA;AAC3C,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAA;AAExD,OAAO,EAAyB,SAAS,EAAE,MAAM,yBAAyB,CAAA;AAC1E,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAA;AAC1D,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAA;AAE1C,MAAM,OAAO,GAAG,aAAa,CAAC,OAAO,IAAI,CAAC,GAAG,CAAC,CAAA;AAE9C,MAAM,CAAC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AM,IAAI,GAAG,aAAa,CAAC,QAAQ;QACjC,CAAC,CAAC,0EAA0E;YAC1E,qCAAqC;YACrC,EAAE;YACF,wDAAwD;YACxD,wDAAwD;YACxD,yBAAyB,CAAC,UAAU;QACtC,CAAC,CAAC,wEAAwE;YACxE,wEAAwE;YACxE,sEAAsE;YACtE,4DAA4D;YAC5D,0EAA0E;YAC1E,mEAAmE;YACnE,WAAW;YACX,yBAAyB,CAAC,cAAc,CAAA;IAE5C,OAAO,KAAK,UAAU,UAAU,CAC9B,GAAoB,EACpB,GAAmB,EACnB,OAEC;QAED,MAAM,cAAc,CAAC,GAAG,EAAE,GAAG,CAAC,CAAA;QAE9B,MAAM,MAAM,GAAG,oBAAoB,CAAC;YAClC,GAAG,OAAO,CAAC,IAAI;YACf,mBAAmB,EAAE,iBAAiB;SACvC,CAAC,CAAA;QAEF,OAAO,SAAS,CACd,GAAG,EACH,aAAa,CAAmB,QAAQ,EAAE,OAAO,EAAE;YACjD,SAAS,EAAE,EAAE,KAAK,EAAE,+BAA+B,EAAE;YACrD,GAAG,EAAE,OAAO,EAAE,GAAG,CAAC,CAAC,CAAC,QAAQ,CAAC,GAAG,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG;YACpD,IAAI,EAAE,OAAO,EAAE,IAAI,IAAI,IAAI;YAC3B,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC;YAC9C,IAAI,EAAE,IAAI,CAAA,uBAAuB;YACjC,OAAO,EAAE,CAAC,MAAM,EAAE,GAAG,OAAO,CAAC;YAC7B,MAAM,EAAE,CAAC,GAAG,MAAM,EAAE,gBAAgB,CAAC;SACtC,CAAC,CACH,CAAA;IACH,CAAC,CAAA;AACH,CAAC","sourcesContent":["import type { IncomingMessage, ServerResponse } from 'node:http'\nimport { createRequire } from 'node:module'\nimport type { HydrationData as UiHydrationData } from '@atproto/oauth-provider-ui/hydration-data'\nimport { buildCustomizationCss } from '../../customization/build-customization-css.js'\nimport { buildCustomizationData } from '../../customization/build-customization-data.js'\nimport type { Customization } from '../../customization/customization.js'\nimport { type CspConfig, mergeCsp } from '../../lib/csp/index.js'\nimport { declareHydrationData } from '../../lib/html/hydration-data.js'\nimport { cssCode, html } from '../../lib/html/index.js'\nimport type { WriteResponseOptions } from '../../lib/http/response.js'\nimport {\n CrossOriginEmbedderPolicy,\n type SecurityHeadersOptions,\n} from '../../lib/http/security-headers.js'\nimport { mergeDefaults } from '../../lib/util/object.js'\nimport type { Simplify } from '../../lib/util/type.js'\nimport { type WriteHtmlOptions, writeHtml } from '../../lib/write-html.js'\nimport { parseAssetsManifest } from './assets-manifest.js'\nimport { setupCsrfToken } from './csrf.js'\n\nconst require = createRequire(import.meta.url)\n\nexport const { getAssets, assetsMiddleware } = parseAssetsManifest(\n require.resolve('@atproto/oauth-provider-ui/bundle-manifest.json'),\n)\n\ntype HydrationData = Simplify<UiHydrationData>\n\nconst SPA_CSP: CspConfig = {\n // API calls are made to the same origin\n 'connect-src': [\"'self'\"],\n // Allow loading of PDS logo & User avatars\n 'img-src': ['data:', 'https:'],\n // Prevent embedding in iframes\n 'frame-ancestors': [\"'none'\"],\n}\n\n/**\n * @see {@link https://docs.hcaptcha.com/#content-security-policy-settings}\n */\nconst HCAPTCHA_CSP: CspConfig = {\n 'script-src': ['https://hcaptcha.com', 'https://*.hcaptcha.com'],\n 'frame-src': ['https://hcaptcha.com', 'https://*.hcaptcha.com'],\n 'style-src': ['https://hcaptcha.com', 'https://*.hcaptcha.com'],\n 'connect-src': ['https://hcaptcha.com', 'https://*.hcaptcha.com'],\n}\n\nexport type SendWebAppOptions = SecurityHeadersOptions & WriteResponseOptions\n\nexport function sendWebAppFactory<P extends keyof HydrationData>(\n page: P,\n customization: Customization,\n defaults: SendWebAppOptions = {},\n) {\n // Pre-computed options:\n const customizationData = buildCustomizationData(customization)\n const customizationCss = cssCode(buildCustomizationCss(customization))\n\n const assets = getAssets(page)\n if (!assets) throw new Error(`No assets found for page: ${page}`)\n\n const { scripts, styles } = assets\n\n const csp = mergeCsp(\n SPA_CSP,\n customization.hcaptcha ? HCAPTCHA_CSP : undefined,\n )\n\n const coep = customization.hcaptcha\n ? // hCaptcha's implementation of COEP is currently broken. Let's disable it\n // to avoid breaking the entire page.\n //\n // https://github.com/hCaptcha/react-hcaptcha/issues/259\n // https://github.com/hCaptcha/react-hcaptcha/issues/380\n CrossOriginEmbedderPolicy.unsafeNone\n : // Since we are loading avatars form other origins, which might not have\n // CORP headers, we need to use the \"credentialless\" value, which allows\n // loading cross-origin resources without credentials (cookies, client\n // certificates, etc.). This is a more secure alternative to\n // \"unsafe-none\". Ideally, we would want to set COEP to \"require-corp\" and\n // ensure that all cross-origin resources have the appropriate CORP\n // headers.\n CrossOriginEmbedderPolicy.credentialless\n\n return async function sendWebApp(\n req: IncomingMessage,\n res: ServerResponse,\n options: SendWebAppOptions & {\n data: Omit<HydrationData[P], '__customizationData'>\n },\n ): Promise<void> {\n await setupCsrfToken(req, res)\n\n const script = declareHydrationData({\n ...options.data,\n __customizationData: customizationData,\n })\n\n return writeHtml(\n res,\n mergeDefaults<WriteHtmlOptions>(defaults, options, {\n bodyAttrs: { class: 'text-foreground bg-background' },\n csp: options?.csp ? mergeCsp(csp, options.csp) : csp,\n coep: options?.coep ?? coep,\n meta: [{ name: 'robots', content: 'noindex' }],\n body: html`<div id=\"root\"></div>`,\n scripts: [script, ...scripts],\n styles: [...styles, customizationCss],\n }),\n )\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-api-middleware.d.ts","sourceRoot":"","sources":["../../src/router/create-api-middleware.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,WAAW,CAAA;AAgChE,OAAO,EAEL,KAAK,UAAU,EAahB,MAAM,sBAAsB,CAAA;AAK7B,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAA;AASzD,OAAO,EAEL,KAAK,oBAAoB,EAM1B,MAAM,2BAA2B,CAAA;AAClC,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAA;AAEhE,wBAAgB,mBAAmB,CACjC,GAAG,SAAS,MAAM,GAAG,IAAI,GAAG,IAAI,EAChC,GAAG,SAAS,eAAe,GAAG,eAAe,EAC7C,GAAG,SAAS,cAAc,GAAG,cAAc,EAE3C,MAAM,EAAE,aAAa,EACrB,EAAE,OAAO,EAAE,EAAE,iBAAiB,CAAC,GAAG,EAAE,GAAG,CAAC,GACvC,UAAU,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,
|
|
1
|
+
{"version":3,"file":"create-api-middleware.d.ts","sourceRoot":"","sources":["../../src/router/create-api-middleware.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,WAAW,CAAA;AAgChE,OAAO,EAEL,KAAK,UAAU,EAahB,MAAM,sBAAsB,CAAA;AAK7B,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAA;AASzD,OAAO,EAEL,KAAK,oBAAoB,EAM1B,MAAM,2BAA2B,CAAA;AAClC,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAA;AAEhE,wBAAgB,mBAAmB,CACjC,GAAG,SAAS,MAAM,GAAG,IAAI,GAAG,IAAI,EAChC,GAAG,SAAS,eAAe,GAAG,eAAe,EAC7C,GAAG,SAAS,cAAc,GAAG,cAAc,EAE3C,MAAM,EAAE,aAAa,EACrB,EAAE,OAAO,EAAE,EAAE,iBAAiB,CAAC,GAAG,EAAE,GAAG,CAAC,GACvC,UAAU,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAk6B3B;AA2BD,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,GAAG,GAAG,oBAAoB,CA4C/D"}
|
|
@@ -43,7 +43,10 @@ export function createApiMiddleware(server, { onError }) {
|
|
|
43
43
|
rotateDeviceCookies: true,
|
|
44
44
|
async handler() {
|
|
45
45
|
const { deviceId, deviceMetadata, input, requestUri } = this;
|
|
46
|
-
const
|
|
46
|
+
const clientId = requestUri
|
|
47
|
+
? await server.requestManager.peekClientId(requestUri)
|
|
48
|
+
: undefined;
|
|
49
|
+
const account = await server.accountManager.createAccount(deviceId, deviceMetadata, input, clientId);
|
|
47
50
|
// Remember when not in the context of a request by default
|
|
48
51
|
const remember = requestUri == null;
|
|
49
52
|
// Only "remember" the newly created account if it was not created during an
|
|
@@ -56,7 +59,7 @@ export function createApiMiddleware(server, { onError }) {
|
|
|
56
59
|
: await server.signer.createEphemeralToken({
|
|
57
60
|
sub: account.did,
|
|
58
61
|
deviceId,
|
|
59
|
-
requestUri
|
|
62
|
+
requestUri,
|
|
60
63
|
});
|
|
61
64
|
const json = { account, ephemeralToken };
|
|
62
65
|
return { json };
|