@executor-js/emulate 0.6.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/README.md +1044 -0
- package/dist/api.d.ts +24 -0
- package/dist/api.js +2665 -0
- package/dist/api.js.map +1 -0
- package/dist/chunk-D6EKRYGP.js +1615 -0
- package/dist/chunk-D6EKRYGP.js.map +1 -0
- package/dist/chunk-WVQMFHQM.js +83 -0
- package/dist/chunk-WVQMFHQM.js.map +1 -0
- package/dist/dist-7FDUSG5I.js +24368 -0
- package/dist/dist-7FDUSG5I.js.map +1 -0
- package/dist/dist-7N4COJHK.js +1814 -0
- package/dist/dist-7N4COJHK.js.map +1 -0
- package/dist/dist-BTEY33DJ.js +2334 -0
- package/dist/dist-BTEY33DJ.js.map +1 -0
- package/dist/dist-DK26ESP2.js +595 -0
- package/dist/dist-DK26ESP2.js.map +1 -0
- package/dist/dist-IYZPDKJW.js +1284 -0
- package/dist/dist-IYZPDKJW.js.map +1 -0
- package/dist/dist-JJ2ZRCAX.js +189 -0
- package/dist/dist-JJ2ZRCAX.js.map +1 -0
- package/dist/dist-K4CVTD6K.js +1570 -0
- package/dist/dist-K4CVTD6K.js.map +1 -0
- package/dist/dist-M3GVASMR.js +1254 -0
- package/dist/dist-M3GVASMR.js.map +1 -0
- package/dist/dist-OYYGWKZQ.js +1533 -0
- package/dist/dist-OYYGWKZQ.js.map +1 -0
- package/dist/dist-P3SBBRFR.js +3169 -0
- package/dist/dist-P3SBBRFR.js.map +1 -0
- package/dist/dist-RMPDKZUA.js +1183 -0
- package/dist/dist-RMPDKZUA.js.map +1 -0
- package/dist/dist-WBKONLOE.js +2154 -0
- package/dist/dist-WBKONLOE.js.map +1 -0
- package/dist/dist-XM5HSBDC.js +1090 -0
- package/dist/dist-XM5HSBDC.js.map +1 -0
- package/dist/dist-XVVIYXQG.js +4241 -0
- package/dist/dist-XVVIYXQG.js.map +1 -0
- package/dist/dist-YPRJYQHW.js +5109 -0
- package/dist/dist-YPRJYQHW.js.map +1 -0
- package/dist/dist-ZEC77OKZ.js +913 -0
- package/dist/dist-ZEC77OKZ.js.map +1 -0
- package/dist/fonts/GeistPixel-Square.woff2 +0 -0
- package/dist/fonts/favicon.ico +0 -0
- package/dist/fonts/geist-sans.woff2 +0 -0
- package/dist/helpers-LXLP3DFE-LBOTATT5.js +17 -0
- package/dist/helpers-LXLP3DFE-LBOTATT5.js.map +1 -0
- package/dist/index.js +3005 -0
- package/dist/index.js.map +1 -0
- package/package.json +83 -0
|
@@ -0,0 +1,913 @@
|
|
|
1
|
+
import {
|
|
2
|
+
SignJWT,
|
|
3
|
+
exportJWK,
|
|
4
|
+
generateKeyPair
|
|
5
|
+
} from "./chunk-D6EKRYGP.js";
|
|
6
|
+
|
|
7
|
+
// ../@emulators/apple/dist/index.js
|
|
8
|
+
import { randomBytes } from "crypto";
|
|
9
|
+
import { randomBytes as randomBytes2 } from "crypto";
|
|
10
|
+
function getAppleStore(store) {
|
|
11
|
+
return {
|
|
12
|
+
users: store.collection("apple.users", ["uid", "email"]),
|
|
13
|
+
oauthClients: store.collection("apple.oauth_clients", ["client_id"])
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
function generateAppleUid() {
|
|
17
|
+
const prefix = randomBytes(3).toString("hex").toUpperCase();
|
|
18
|
+
const middle = randomBytes(16).toString("hex");
|
|
19
|
+
const suffix = randomBytes(2).toString("hex").toUpperCase();
|
|
20
|
+
return `${prefix}.${middle}.${suffix}`;
|
|
21
|
+
}
|
|
22
|
+
function generatePrivateRelayEmail() {
|
|
23
|
+
const id = randomBytes(12).toString("hex");
|
|
24
|
+
return `${id}@privaterelay.appleid.com`;
|
|
25
|
+
}
|
|
26
|
+
function createErrorHandler(documentationUrl) {
|
|
27
|
+
return async (c, next) => {
|
|
28
|
+
if (documentationUrl) {
|
|
29
|
+
c.set("docsUrl", documentationUrl);
|
|
30
|
+
}
|
|
31
|
+
await next();
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
var errorHandler = createErrorHandler();
|
|
35
|
+
var isDebug = typeof process !== "undefined" && (process.env.DEBUG === "1" || process.env.DEBUG === "true" || process.env.EMULATE_DEBUG === "1");
|
|
36
|
+
function debug(label, ...args) {
|
|
37
|
+
if (isDebug) {
|
|
38
|
+
console.log(`[${label}]`, ...args);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
function escapeHtml(s) {
|
|
42
|
+
return s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
43
|
+
}
|
|
44
|
+
function escapeAttr(s) {
|
|
45
|
+
return escapeHtml(s).replace(/'/g, "'");
|
|
46
|
+
}
|
|
47
|
+
var CSS = `
|
|
48
|
+
@font-face{
|
|
49
|
+
font-family:'Geist';font-style:normal;font-weight:100 900;font-display:swap;
|
|
50
|
+
src:url('/_emulate/fonts/geist-sans.woff2') format('woff2');
|
|
51
|
+
}
|
|
52
|
+
@font-face{
|
|
53
|
+
font-family:'Geist Pixel';font-style:normal;font-weight:400;font-display:swap;
|
|
54
|
+
src:url('/_emulate/fonts/GeistPixel-Square.woff2') format('woff2');
|
|
55
|
+
}
|
|
56
|
+
*{box-sizing:border-box;margin:0;padding:0}
|
|
57
|
+
body{
|
|
58
|
+
font-family:'Geist',-apple-system,BlinkMacSystemFont,sans-serif;
|
|
59
|
+
background:#000;color:#33ff00;min-height:100vh;
|
|
60
|
+
-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale;
|
|
61
|
+
}
|
|
62
|
+
.emu-bar{
|
|
63
|
+
border-bottom:1px solid #0a3300;padding:10px 20px;
|
|
64
|
+
display:flex;align-items:center;gap:10px;font-size:.8125rem;color:#1a8c00;
|
|
65
|
+
}
|
|
66
|
+
.emu-bar-title{font-weight:600;color:#33ff00;font-family:'Geist Pixel',monospace;}
|
|
67
|
+
.emu-bar-links{margin-left:auto;display:flex;gap:16px;}
|
|
68
|
+
.emu-bar-links a{
|
|
69
|
+
color:#1a8c00;font-size:.75rem;text-decoration:none;transition:color .15s;
|
|
70
|
+
}
|
|
71
|
+
.emu-bar-links a:hover{color:#33ff00;}
|
|
72
|
+
.emu-bar-links a .full{display:inline;}
|
|
73
|
+
.emu-bar-links a .short{display:none;}
|
|
74
|
+
@media(max-width:600px){
|
|
75
|
+
.emu-bar-links a .full{display:none;}
|
|
76
|
+
.emu-bar-links a .short{display:inline;}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
.content{
|
|
80
|
+
display:flex;align-items:center;justify-content:center;
|
|
81
|
+
min-height:calc(100vh - 42px);padding:24px 16px;
|
|
82
|
+
}
|
|
83
|
+
.content-inner{width:100%;max-width:420px;}
|
|
84
|
+
.card-title{
|
|
85
|
+
font-family:'Geist Pixel',monospace;
|
|
86
|
+
font-size:1.125rem;font-weight:600;margin-bottom:4px;color:#33ff00;
|
|
87
|
+
}
|
|
88
|
+
.card-subtitle{color:#1a8c00;font-size:.8125rem;margin-bottom:18px;line-height:1.45;}
|
|
89
|
+
.powered-by{
|
|
90
|
+
position:fixed;bottom:0;left:0;right:0;
|
|
91
|
+
text-align:center;padding:12px;font-size:.6875rem;color:#0a3300;
|
|
92
|
+
font-family:'Geist Pixel',monospace;
|
|
93
|
+
}
|
|
94
|
+
.powered-by a{color:#1a8c00;text-decoration:none;transition:color .15s;}
|
|
95
|
+
.powered-by a:hover{color:#33ff00;}
|
|
96
|
+
|
|
97
|
+
.error-title{
|
|
98
|
+
font-family:'Geist Pixel',monospace;
|
|
99
|
+
color:#ff4444;font-size:1.125rem;font-weight:600;margin-bottom:8px;
|
|
100
|
+
}
|
|
101
|
+
.error-msg{color:#1a8c00;font-size:.875rem;line-height:1.5;}
|
|
102
|
+
.error-card{text-align:center;}
|
|
103
|
+
|
|
104
|
+
.user-form{margin-bottom:8px;}
|
|
105
|
+
.user-form:last-of-type{margin-bottom:0;}
|
|
106
|
+
.user-btn{
|
|
107
|
+
width:100%;display:flex;align-items:center;gap:12px;
|
|
108
|
+
padding:10px 12px;border:1px solid #0a3300;border-radius:8px;
|
|
109
|
+
background:#000;color:inherit;cursor:pointer;text-align:left;
|
|
110
|
+
font:inherit;transition:border-color .15s;
|
|
111
|
+
}
|
|
112
|
+
.user-btn:hover{border-color:#33ff00;}
|
|
113
|
+
.avatar{
|
|
114
|
+
width:36px;height:36px;border-radius:50%;
|
|
115
|
+
background:#0a3300;color:#33ff00;font-weight:600;font-size:.875rem;
|
|
116
|
+
display:flex;align-items:center;justify-content:center;flex-shrink:0;
|
|
117
|
+
font-family:'Geist Pixel',monospace;
|
|
118
|
+
}
|
|
119
|
+
.user-text{min-width:0;}
|
|
120
|
+
.user-login{font-weight:600;font-size:.875rem;display:block;color:#33ff00;}
|
|
121
|
+
.user-meta{color:#1a8c00;font-size:.75rem;margin-top:1px;}
|
|
122
|
+
.user-email{font-size:.6875rem;color:#116600;word-break:break-all;margin-top:1px;}
|
|
123
|
+
|
|
124
|
+
.settings-layout{
|
|
125
|
+
max-width:920px;margin:0 auto;padding:28px 20px;
|
|
126
|
+
display:flex;gap:28px;
|
|
127
|
+
}
|
|
128
|
+
.settings-sidebar{width:200px;flex-shrink:0;}
|
|
129
|
+
.settings-sidebar a{
|
|
130
|
+
display:block;padding:6px 10px;border-radius:6px;color:#1a8c00;
|
|
131
|
+
text-decoration:none;font-size:.8125rem;transition:color .15s;
|
|
132
|
+
}
|
|
133
|
+
.settings-sidebar a:hover{color:#33ff00;}
|
|
134
|
+
.settings-sidebar a.active{color:#33ff00;font-weight:600;}
|
|
135
|
+
.settings-main{flex:1;min-width:0;}
|
|
136
|
+
|
|
137
|
+
.s-card{
|
|
138
|
+
padding:18px 0;margin-bottom:14px;border-bottom:1px solid #0a3300;
|
|
139
|
+
}
|
|
140
|
+
.s-card:last-child{border-bottom:none;}
|
|
141
|
+
.s-card-header{display:flex;align-items:center;gap:14px;margin-bottom:14px;}
|
|
142
|
+
.s-icon{
|
|
143
|
+
width:42px;height:42px;border-radius:8px;
|
|
144
|
+
background:#0a3300;display:flex;align-items:center;justify-content:center;
|
|
145
|
+
font-size:1.125rem;font-weight:700;color:#116600;flex-shrink:0;
|
|
146
|
+
font-family:'Geist Pixel',monospace;
|
|
147
|
+
}
|
|
148
|
+
.s-title{
|
|
149
|
+
font-family:'Geist Pixel',monospace;
|
|
150
|
+
font-size:1.25rem;font-weight:600;color:#33ff00;
|
|
151
|
+
}
|
|
152
|
+
.s-subtitle{font-size:.75rem;color:#1a8c00;margin-top:2px;}
|
|
153
|
+
.section-heading{
|
|
154
|
+
font-size:.9375rem;font-weight:600;margin-bottom:10px;color:#33ff00;
|
|
155
|
+
display:flex;align-items:center;justify-content:space-between;
|
|
156
|
+
}
|
|
157
|
+
.perm-list{list-style:none;}
|
|
158
|
+
.perm-list li{padding:5px 0;font-size:.8125rem;display:flex;align-items:center;gap:6px;color:#1a8c00;}
|
|
159
|
+
.check{color:#33ff00;}
|
|
160
|
+
.org-row{
|
|
161
|
+
display:flex;align-items:center;gap:8px;padding:7px 0;
|
|
162
|
+
border-bottom:1px solid #0a3300;font-size:.8125rem;
|
|
163
|
+
}
|
|
164
|
+
.org-row:last-child{border-bottom:none;}
|
|
165
|
+
.org-icon{
|
|
166
|
+
width:22px;height:22px;border-radius:4px;background:#0a3300;
|
|
167
|
+
display:flex;align-items:center;justify-content:center;
|
|
168
|
+
font-size:.625rem;font-weight:700;color:#116600;flex-shrink:0;
|
|
169
|
+
font-family:'Geist Pixel',monospace;
|
|
170
|
+
}
|
|
171
|
+
.org-name{font-weight:600;color:#33ff00;}
|
|
172
|
+
.badge{font-size:.6875rem;padding:1px 7px;border-radius:999px;font-weight:500;}
|
|
173
|
+
.badge-granted{background:#0a3300;color:#33ff00;}
|
|
174
|
+
.badge-denied{background:#1a0a0a;color:#ff4444;}
|
|
175
|
+
.badge-requested{background:#0a3300;color:#1a8c00;}
|
|
176
|
+
.btn-revoke{
|
|
177
|
+
display:inline-block;padding:5px 14px;border-radius:6px;
|
|
178
|
+
border:1px solid #0a3300;background:transparent;color:#ff4444;
|
|
179
|
+
font-size:.75rem;font-weight:600;cursor:pointer;transition:border-color .15s;
|
|
180
|
+
}
|
|
181
|
+
.btn-revoke:hover{border-color:#ff4444;}
|
|
182
|
+
.info-text{color:#1a8c00;font-size:.75rem;line-height:1.5;margin-top:10px;}
|
|
183
|
+
.info-text a,.section-heading a{color:#1a8c00;text-decoration:none;transition:color .15s;}
|
|
184
|
+
.info-text a:hover,.section-heading a:hover{color:#33ff00;}
|
|
185
|
+
code{font-family:'Geist Mono','SF Mono',ui-monospace,monospace;font-size:.8125rem;color:#33ff00;word-break:break-all;}
|
|
186
|
+
.code-block{
|
|
187
|
+
background:#020;border:1px solid #0a3300;border-radius:6px;padding:10px 12px;
|
|
188
|
+
margin:8px 0 12px;overflow-x:auto;
|
|
189
|
+
}
|
|
190
|
+
.code-block code{white-space:pre;word-break:normal;display:block;line-height:1.5;}
|
|
191
|
+
.app-link{
|
|
192
|
+
display:flex;align-items:center;gap:12px;padding:12px;
|
|
193
|
+
border:1px solid #0a3300;border-radius:8px;background:#000;
|
|
194
|
+
text-decoration:none;color:inherit;margin-bottom:8px;transition:border-color .15s;
|
|
195
|
+
}
|
|
196
|
+
.app-link:hover{border-color:#33ff00;}
|
|
197
|
+
.app-link-name{font-weight:600;font-size:.875rem;color:#33ff00;}
|
|
198
|
+
.app-link-scopes{font-size:.6875rem;color:#1a8c00;margin-top:1px;}
|
|
199
|
+
.empty{color:#1a8c00;text-align:center;padding:28px 0;font-size:.875rem;}
|
|
200
|
+
|
|
201
|
+
.inspector-layout{max-width:960px;margin:0 auto;padding:28px 20px;}
|
|
202
|
+
.inspector-tabs{display:flex;gap:4px;margin-bottom:20px;}
|
|
203
|
+
.inspector-tabs a{
|
|
204
|
+
padding:7px 16px;border-radius:6px;text-decoration:none;
|
|
205
|
+
font-size:.8125rem;color:#1a8c00;border:1px solid transparent;
|
|
206
|
+
transition:color .15s,border-color .15s;
|
|
207
|
+
}
|
|
208
|
+
.inspector-tabs a:hover{color:#33ff00;}
|
|
209
|
+
.inspector-tabs a.active{color:#33ff00;font-weight:600;border-color:#0a3300;background:#0a3300;}
|
|
210
|
+
.inspector-section{margin-bottom:24px;}
|
|
211
|
+
.inspector-section h2{
|
|
212
|
+
font-family:'Geist Pixel',monospace;
|
|
213
|
+
font-size:1rem;font-weight:600;color:#33ff00;margin-bottom:10px;
|
|
214
|
+
}
|
|
215
|
+
.inspector-section h3{
|
|
216
|
+
font-family:'Geist Pixel',monospace;
|
|
217
|
+
font-size:.875rem;font-weight:600;color:#1a8c00;margin:16px 0 8px;
|
|
218
|
+
}
|
|
219
|
+
.inspector-table{width:100%;border-collapse:collapse;margin-bottom:12px;}
|
|
220
|
+
.inspector-table th,.inspector-table td{
|
|
221
|
+
text-align:left;padding:8px 12px;border-bottom:1px solid #0a3300;
|
|
222
|
+
font-size:.8125rem;
|
|
223
|
+
}
|
|
224
|
+
.inspector-table th{color:#1a8c00;font-weight:600;font-size:.75rem;text-transform:uppercase;letter-spacing:.04em;}
|
|
225
|
+
.inspector-table td{color:#33ff00;}
|
|
226
|
+
.inspector-table tbody tr{transition:background .1s;}
|
|
227
|
+
.inspector-table tbody tr:hover{background:#0a3300;}
|
|
228
|
+
.inspector-empty{color:#1a8c00;text-align:center;padding:20px 0;font-size:.8125rem;}
|
|
229
|
+
|
|
230
|
+
.checkout-layout{
|
|
231
|
+
display:flex;min-height:calc(100vh - 42px);
|
|
232
|
+
}
|
|
233
|
+
.checkout-summary{
|
|
234
|
+
flex:1;background:#020;padding:48px 40px 48px 10%;
|
|
235
|
+
display:flex;flex-direction:column;justify-content:center;
|
|
236
|
+
border-right:1px solid #0a3300;
|
|
237
|
+
}
|
|
238
|
+
.checkout-form-side{
|
|
239
|
+
flex:1;background:#000;padding:48px 10% 48px 40px;
|
|
240
|
+
display:flex;flex-direction:column;justify-content:center;
|
|
241
|
+
}
|
|
242
|
+
.checkout-merchant{
|
|
243
|
+
display:flex;align-items:center;gap:10px;margin-bottom:6px;
|
|
244
|
+
}
|
|
245
|
+
.checkout-merchant-name{
|
|
246
|
+
font-family:'Geist Pixel',monospace;
|
|
247
|
+
font-size:.9375rem;font-weight:600;color:#33ff00;
|
|
248
|
+
}
|
|
249
|
+
.checkout-test-badge{
|
|
250
|
+
font-size:.625rem;font-weight:700;letter-spacing:.04em;text-transform:uppercase;
|
|
251
|
+
background:#0a3300;color:#1a8c00;padding:2px 8px;border-radius:4px;
|
|
252
|
+
}
|
|
253
|
+
.checkout-total{
|
|
254
|
+
font-family:'Geist Pixel',monospace;
|
|
255
|
+
font-size:2rem;font-weight:700;color:#33ff00;margin:8px 0 28px;
|
|
256
|
+
}
|
|
257
|
+
.checkout-line-item{
|
|
258
|
+
display:flex;align-items:center;gap:14px;padding:14px 0;
|
|
259
|
+
border-bottom:1px solid #0a3300;
|
|
260
|
+
}
|
|
261
|
+
.checkout-line-item:first-child{border-top:1px solid #0a3300;}
|
|
262
|
+
.checkout-item-icon{
|
|
263
|
+
width:42px;height:42px;border-radius:6px;background:#0a3300;
|
|
264
|
+
display:flex;align-items:center;justify-content:center;flex-shrink:0;
|
|
265
|
+
font-family:'Geist Pixel',monospace;font-size:.875rem;font-weight:700;color:#116600;
|
|
266
|
+
}
|
|
267
|
+
.checkout-item-details{flex:1;min-width:0;}
|
|
268
|
+
.checkout-item-name{font-size:.875rem;font-weight:600;color:#33ff00;}
|
|
269
|
+
.checkout-item-qty{font-size:.75rem;color:#1a8c00;margin-top:2px;}
|
|
270
|
+
.checkout-item-price{
|
|
271
|
+
font-size:.875rem;font-weight:600;color:#33ff00;text-align:right;white-space:nowrap;
|
|
272
|
+
}
|
|
273
|
+
.checkout-item-unit{font-size:.6875rem;color:#1a8c00;text-align:right;margin-top:2px;}
|
|
274
|
+
.checkout-totals{margin-top:20px;}
|
|
275
|
+
.checkout-totals-row{
|
|
276
|
+
display:flex;justify-content:space-between;padding:6px 0;
|
|
277
|
+
font-size:.8125rem;color:#1a8c00;
|
|
278
|
+
}
|
|
279
|
+
.checkout-totals-row.total{
|
|
280
|
+
border-top:1px solid #0a3300;margin-top:8px;padding-top:14px;
|
|
281
|
+
font-size:.9375rem;font-weight:600;color:#33ff00;
|
|
282
|
+
}
|
|
283
|
+
.checkout-form-section{margin-bottom:24px;}
|
|
284
|
+
.checkout-form-label{
|
|
285
|
+
font-size:.8125rem;font-weight:600;color:#33ff00;margin-bottom:8px;display:block;
|
|
286
|
+
}
|
|
287
|
+
.checkout-input{
|
|
288
|
+
width:100%;padding:10px 12px;border:1px solid #0a3300;border-radius:6px;
|
|
289
|
+
background:#020;color:#33ff00;font:inherit;font-size:.875rem;
|
|
290
|
+
transition:border-color .15s;outline:none;
|
|
291
|
+
}
|
|
292
|
+
.checkout-input:focus{border-color:#33ff00;}
|
|
293
|
+
.checkout-input::placeholder{color:#116600;}
|
|
294
|
+
.checkout-card-box{
|
|
295
|
+
border:1px solid #0a3300;border-radius:6px;padding:14px;
|
|
296
|
+
background:#020;
|
|
297
|
+
}
|
|
298
|
+
.checkout-card-row{
|
|
299
|
+
display:flex;gap:12px;margin-top:10px;
|
|
300
|
+
}
|
|
301
|
+
.checkout-card-row .checkout-input{flex:1;}
|
|
302
|
+
.checkout-sim-note{
|
|
303
|
+
font-size:.6875rem;color:#1a8c00;margin-top:10px;text-align:center;
|
|
304
|
+
font-style:italic;
|
|
305
|
+
}
|
|
306
|
+
.checkout-pay-btn{
|
|
307
|
+
width:100%;padding:14px;border:none;border-radius:8px;
|
|
308
|
+
background:#33ff00;color:#000;font:inherit;font-size:.9375rem;font-weight:700;
|
|
309
|
+
cursor:pointer;transition:background .15s;
|
|
310
|
+
font-family:'Geist Pixel',monospace;
|
|
311
|
+
}
|
|
312
|
+
.checkout-pay-btn:hover{background:#44ff22;}
|
|
313
|
+
.checkout-cancel{
|
|
314
|
+
text-align:center;margin-top:14px;
|
|
315
|
+
}
|
|
316
|
+
.checkout-cancel a{
|
|
317
|
+
color:#1a8c00;text-decoration:none;font-size:.8125rem;
|
|
318
|
+
transition:color .15s;
|
|
319
|
+
}
|
|
320
|
+
.checkout-cancel a:hover{color:#33ff00;}
|
|
321
|
+
@media(max-width:768px){
|
|
322
|
+
.checkout-layout{flex-direction:column;}
|
|
323
|
+
.checkout-summary{padding:32px 20px;border-right:none;border-bottom:1px solid #0a3300;}
|
|
324
|
+
.checkout-form-side{padding:32px 20px;}
|
|
325
|
+
}
|
|
326
|
+
`;
|
|
327
|
+
var POWERED_BY = `<div class="powered-by">Powered by <a href="https://emulate.dev" target="_blank" rel="noopener">emulate</a></div>`;
|
|
328
|
+
function emuBar(service) {
|
|
329
|
+
const title = service ? `${escapeHtml(service)} Emulator` : "Emulator";
|
|
330
|
+
return `<div class="emu-bar">
|
|
331
|
+
<span class="emu-bar-title">${title}</span>
|
|
332
|
+
<nav class="emu-bar-links">
|
|
333
|
+
<a href="https://github.com/vercel-labs/emulate/issues" target="_blank" rel="noopener"><span class="full">Report Issue</span><span class="short">Report</span></a>
|
|
334
|
+
<a href="https://github.com/vercel-labs/emulate" target="_blank" rel="noopener"><span class="full">Source Code</span><span class="short">Source</span></a>
|
|
335
|
+
<a href="https://emulate.dev" target="_blank" rel="noopener"><span class="full">Learn More</span><span class="short">Learn</span></a>
|
|
336
|
+
</nav>
|
|
337
|
+
</div>`;
|
|
338
|
+
}
|
|
339
|
+
function head(title) {
|
|
340
|
+
return `<!DOCTYPE html>
|
|
341
|
+
<html lang="en">
|
|
342
|
+
<head>
|
|
343
|
+
<meta charset="utf-8"/>
|
|
344
|
+
<meta name="viewport" content="width=device-width,initial-scale=1"/>
|
|
345
|
+
<link rel="icon" href="/_emulate/favicon.ico"/>
|
|
346
|
+
<title>${escapeHtml(title)} | emulate</title>
|
|
347
|
+
<style>${CSS}</style>
|
|
348
|
+
</head>`;
|
|
349
|
+
}
|
|
350
|
+
function renderCardPage(title, subtitle, body, service) {
|
|
351
|
+
return `${head(title)}
|
|
352
|
+
<body>
|
|
353
|
+
${emuBar(service)}
|
|
354
|
+
<div class="content">
|
|
355
|
+
<div class="content-inner">
|
|
356
|
+
<div class="card-title">${escapeHtml(title)}</div>
|
|
357
|
+
<div class="card-subtitle">${subtitle}</div>
|
|
358
|
+
${body}
|
|
359
|
+
</div>
|
|
360
|
+
</div>
|
|
361
|
+
${POWERED_BY}
|
|
362
|
+
</body></html>`;
|
|
363
|
+
}
|
|
364
|
+
function renderErrorPage(title, message, service) {
|
|
365
|
+
return `${head(title)}
|
|
366
|
+
<body>
|
|
367
|
+
${emuBar(service)}
|
|
368
|
+
<div class="content">
|
|
369
|
+
<div class="content-inner error-card">
|
|
370
|
+
<div class="error-title">${escapeHtml(title)}</div>
|
|
371
|
+
<div class="error-msg">${escapeHtml(message)}</div>
|
|
372
|
+
</div>
|
|
373
|
+
</div>
|
|
374
|
+
${POWERED_BY}
|
|
375
|
+
</body></html>`;
|
|
376
|
+
}
|
|
377
|
+
function renderFormPostPage(action, fields, service) {
|
|
378
|
+
const hiddens = Object.entries(fields).filter(([, v]) => v != null).map(([k, v]) => `<input type="hidden" name="${escapeAttr(k)}" value="${escapeAttr(v)}"/>`).join("\n");
|
|
379
|
+
return `${head("Redirecting")}
|
|
380
|
+
<body onload="document.forms[0].submit()">
|
|
381
|
+
${emuBar(service)}
|
|
382
|
+
<div class="content">
|
|
383
|
+
<div class="content-inner" style="text-align:center">
|
|
384
|
+
<div class="card-subtitle">Redirecting…</div>
|
|
385
|
+
<form method="POST" action="${escapeAttr(action)}">
|
|
386
|
+
${hiddens}
|
|
387
|
+
<noscript><button type="submit" class="user-btn" style="margin-top:12px;justify-content:center">
|
|
388
|
+
<span class="user-login">Continue</span>
|
|
389
|
+
</button></noscript>
|
|
390
|
+
</form>
|
|
391
|
+
</div>
|
|
392
|
+
</div>
|
|
393
|
+
${POWERED_BY}
|
|
394
|
+
</body></html>`;
|
|
395
|
+
}
|
|
396
|
+
function renderUserButton(opts) {
|
|
397
|
+
const hiddens = Object.entries(opts.hiddenFields).map(([k, v]) => `<input type="hidden" name="${escapeAttr(k)}" value="${escapeAttr(v)}"/>`).join("");
|
|
398
|
+
const nameLine = opts.name ? `<div class="user-meta">${escapeHtml(opts.name)}</div>` : "";
|
|
399
|
+
const emailLine = opts.email ? `<div class="user-email">${escapeHtml(opts.email)}</div>` : "";
|
|
400
|
+
return `<form class="user-form" method="post" action="${escapeAttr(opts.formAction)}">
|
|
401
|
+
${hiddens}
|
|
402
|
+
<button type="submit" class="user-btn">
|
|
403
|
+
<span class="avatar">${escapeHtml(opts.letter)}</span>
|
|
404
|
+
<span class="user-text">
|
|
405
|
+
<span class="user-login">${escapeHtml(opts.login)}</span>
|
|
406
|
+
${nameLine}${emailLine}
|
|
407
|
+
</span>
|
|
408
|
+
</button>
|
|
409
|
+
</form>`;
|
|
410
|
+
}
|
|
411
|
+
function normalizeUri(uri) {
|
|
412
|
+
try {
|
|
413
|
+
const u = new URL(uri);
|
|
414
|
+
return `${u.origin}${u.pathname.replace(/\/+$/, "")}`;
|
|
415
|
+
} catch {
|
|
416
|
+
return uri.replace(/\/+$/, "").split("?")[0];
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
function matchesRedirectUri(incoming, registered) {
|
|
420
|
+
const normalized = normalizeUri(incoming);
|
|
421
|
+
return registered.some((r) => normalizeUri(r) === normalized);
|
|
422
|
+
}
|
|
423
|
+
function bodyStr(v) {
|
|
424
|
+
if (typeof v === "string") return v;
|
|
425
|
+
if (Array.isArray(v) && typeof v[0] === "string") return v[0];
|
|
426
|
+
return "";
|
|
427
|
+
}
|
|
428
|
+
var keyPairPromise = generateKeyPair("RS256");
|
|
429
|
+
var KID = "emulate-apple-1";
|
|
430
|
+
var PENDING_CODE_TTL_MS = 5 * 60 * 1e3;
|
|
431
|
+
function getPendingCodes(store) {
|
|
432
|
+
let map = store.getData("apple.oauth.pendingCodes");
|
|
433
|
+
if (!map) {
|
|
434
|
+
map = /* @__PURE__ */ new Map();
|
|
435
|
+
store.setData("apple.oauth.pendingCodes", map);
|
|
436
|
+
}
|
|
437
|
+
return map;
|
|
438
|
+
}
|
|
439
|
+
function getRefreshTokens(store) {
|
|
440
|
+
let map = store.getData("apple.oauth.refreshTokens");
|
|
441
|
+
if (!map) {
|
|
442
|
+
map = /* @__PURE__ */ new Map();
|
|
443
|
+
store.setData("apple.oauth.refreshTokens", map);
|
|
444
|
+
}
|
|
445
|
+
return map;
|
|
446
|
+
}
|
|
447
|
+
function getFirstAuthTracker(store) {
|
|
448
|
+
let set = store.getData("apple.oauth.firstAuthTracker");
|
|
449
|
+
if (!set) {
|
|
450
|
+
set = /* @__PURE__ */ new Set();
|
|
451
|
+
store.setData("apple.oauth.firstAuthTracker", set);
|
|
452
|
+
}
|
|
453
|
+
return set;
|
|
454
|
+
}
|
|
455
|
+
function isPendingCodeExpired(p) {
|
|
456
|
+
return Date.now() - p.created_at > PENDING_CODE_TTL_MS;
|
|
457
|
+
}
|
|
458
|
+
var SERVICE_LABEL = "Apple";
|
|
459
|
+
async function createIdToken(user, clientId, nonce, baseUrl) {
|
|
460
|
+
const { privateKey } = await keyPairPromise;
|
|
461
|
+
const email = user.is_private_email && user.private_relay_email ? user.private_relay_email : user.email;
|
|
462
|
+
const now = Math.floor(Date.now() / 1e3);
|
|
463
|
+
const builder = new SignJWT({
|
|
464
|
+
sub: user.uid,
|
|
465
|
+
email,
|
|
466
|
+
email_verified: String(user.email_verified),
|
|
467
|
+
is_private_email: String(user.is_private_email),
|
|
468
|
+
real_user_status: user.real_user_status,
|
|
469
|
+
nonce_supported: true,
|
|
470
|
+
auth_time: now,
|
|
471
|
+
...nonce ? { nonce } : {}
|
|
472
|
+
}).setProtectedHeader({ alg: "RS256", kid: KID, typ: "JWT" }).setIssuer(baseUrl).setAudience(clientId).setIssuedAt(now).setExpirationTime("1h");
|
|
473
|
+
return builder.sign(privateKey);
|
|
474
|
+
}
|
|
475
|
+
function oauthRoutes({ app, store, baseUrl, tokenMap }) {
|
|
476
|
+
const as = getAppleStore(store);
|
|
477
|
+
app.get("/.well-known/openid-configuration", (c) => {
|
|
478
|
+
return c.json({
|
|
479
|
+
issuer: baseUrl,
|
|
480
|
+
authorization_endpoint: `${baseUrl}/auth/authorize`,
|
|
481
|
+
token_endpoint: `${baseUrl}/auth/token`,
|
|
482
|
+
revocation_endpoint: `${baseUrl}/auth/revoke`,
|
|
483
|
+
jwks_uri: `${baseUrl}/auth/keys`,
|
|
484
|
+
response_types_supported: ["code"],
|
|
485
|
+
response_modes_supported: ["query", "fragment", "form_post"],
|
|
486
|
+
subject_types_supported: ["pairwise"],
|
|
487
|
+
id_token_signing_alg_values_supported: ["RS256"],
|
|
488
|
+
scopes_supported: ["openid", "email", "name"],
|
|
489
|
+
token_endpoint_auth_methods_supported: ["client_secret_post"],
|
|
490
|
+
claims_supported: [
|
|
491
|
+
"aud",
|
|
492
|
+
"email",
|
|
493
|
+
"email_verified",
|
|
494
|
+
"exp",
|
|
495
|
+
"iat",
|
|
496
|
+
"is_private_email",
|
|
497
|
+
"iss",
|
|
498
|
+
"nonce",
|
|
499
|
+
"nonce_supported",
|
|
500
|
+
"real_user_status",
|
|
501
|
+
"sub",
|
|
502
|
+
"transfer_sub"
|
|
503
|
+
]
|
|
504
|
+
});
|
|
505
|
+
});
|
|
506
|
+
app.get("/auth/keys", async (c) => {
|
|
507
|
+
const { publicKey } = await keyPairPromise;
|
|
508
|
+
const jwk = await exportJWK(publicKey);
|
|
509
|
+
return c.json({
|
|
510
|
+
keys: [
|
|
511
|
+
{
|
|
512
|
+
...jwk,
|
|
513
|
+
kid: KID,
|
|
514
|
+
use: "sig",
|
|
515
|
+
alg: "RS256"
|
|
516
|
+
}
|
|
517
|
+
]
|
|
518
|
+
});
|
|
519
|
+
});
|
|
520
|
+
app.get("/auth/authorize", (c) => {
|
|
521
|
+
const client_id = c.req.query("client_id") ?? "";
|
|
522
|
+
const redirect_uri = c.req.query("redirect_uri") ?? "";
|
|
523
|
+
const scope = c.req.query("scope") ?? "";
|
|
524
|
+
const state = c.req.query("state") ?? "";
|
|
525
|
+
const nonce = c.req.query("nonce") ?? "";
|
|
526
|
+
const response_mode = c.req.query("response_mode") ?? "query";
|
|
527
|
+
const clientsConfigured = as.oauthClients.all().length > 0;
|
|
528
|
+
let clientName = "";
|
|
529
|
+
if (clientsConfigured) {
|
|
530
|
+
const client = as.oauthClients.findOneBy("client_id", client_id);
|
|
531
|
+
if (!client) {
|
|
532
|
+
return c.html(
|
|
533
|
+
renderErrorPage("Application not found", `The client_id '${client_id}' is not registered.`, SERVICE_LABEL),
|
|
534
|
+
400
|
|
535
|
+
);
|
|
536
|
+
}
|
|
537
|
+
if (redirect_uri && !matchesRedirectUri(redirect_uri, client.redirect_uris)) {
|
|
538
|
+
return c.html(
|
|
539
|
+
renderErrorPage(
|
|
540
|
+
"Redirect URI mismatch",
|
|
541
|
+
"The redirect_uri is not registered for this application.",
|
|
542
|
+
SERVICE_LABEL
|
|
543
|
+
),
|
|
544
|
+
400
|
|
545
|
+
);
|
|
546
|
+
}
|
|
547
|
+
clientName = client.name;
|
|
548
|
+
}
|
|
549
|
+
const subtitleText = clientName ? `Sign in to <strong>${escapeHtml(clientName)}</strong> with your Apple ID.` : "Choose a seeded user to continue.";
|
|
550
|
+
const users = as.users.all();
|
|
551
|
+
const userButtons = users.map((user) => {
|
|
552
|
+
return renderUserButton({
|
|
553
|
+
letter: (user.email[0] ?? "?").toUpperCase(),
|
|
554
|
+
login: user.email,
|
|
555
|
+
name: user.name,
|
|
556
|
+
email: user.email,
|
|
557
|
+
formAction: "/auth/authorize/callback",
|
|
558
|
+
hiddenFields: {
|
|
559
|
+
email: user.email,
|
|
560
|
+
redirect_uri,
|
|
561
|
+
scope,
|
|
562
|
+
state,
|
|
563
|
+
nonce,
|
|
564
|
+
client_id,
|
|
565
|
+
response_mode
|
|
566
|
+
}
|
|
567
|
+
});
|
|
568
|
+
}).join("\n");
|
|
569
|
+
const body = users.length === 0 ? '<p class="empty">No users in the emulator store.</p>' : userButtons;
|
|
570
|
+
return c.html(renderCardPage("Sign in with Apple", subtitleText, body, SERVICE_LABEL));
|
|
571
|
+
});
|
|
572
|
+
app.post("/auth/authorize/callback", async (c) => {
|
|
573
|
+
const body = await c.req.parseBody();
|
|
574
|
+
const email = bodyStr(body.email);
|
|
575
|
+
const redirect_uri = bodyStr(body.redirect_uri);
|
|
576
|
+
const scope = bodyStr(body.scope);
|
|
577
|
+
const state = bodyStr(body.state);
|
|
578
|
+
const client_id = bodyStr(body.client_id);
|
|
579
|
+
const nonce = bodyStr(body.nonce);
|
|
580
|
+
const response_mode = bodyStr(body.response_mode) || "query";
|
|
581
|
+
const code = randomBytes2(20).toString("hex");
|
|
582
|
+
getPendingCodes(store).set(code, {
|
|
583
|
+
email,
|
|
584
|
+
scope,
|
|
585
|
+
redirectUri: redirect_uri,
|
|
586
|
+
clientId: client_id,
|
|
587
|
+
nonce: nonce || null,
|
|
588
|
+
responseMode: response_mode,
|
|
589
|
+
created_at: Date.now()
|
|
590
|
+
});
|
|
591
|
+
debug("apple.oauth", `[Apple callback] code=${code.slice(0, 8)}... email=${email}`);
|
|
592
|
+
const tracker = getFirstAuthTracker(store);
|
|
593
|
+
const pairKey = `${email}:${client_id}`;
|
|
594
|
+
const isFirstAuth = !tracker.has(pairKey);
|
|
595
|
+
if (isFirstAuth) {
|
|
596
|
+
tracker.add(pairKey);
|
|
597
|
+
}
|
|
598
|
+
let userJson;
|
|
599
|
+
if (isFirstAuth) {
|
|
600
|
+
const user = as.users.findOneBy("email", email);
|
|
601
|
+
if (user) {
|
|
602
|
+
userJson = JSON.stringify({
|
|
603
|
+
name: { firstName: user.given_name, lastName: user.family_name },
|
|
604
|
+
email: user.email
|
|
605
|
+
});
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
if (response_mode === "form_post") {
|
|
609
|
+
const fields = { code, state };
|
|
610
|
+
if (userJson) fields.user = userJson;
|
|
611
|
+
return c.html(renderFormPostPage(redirect_uri, fields, SERVICE_LABEL));
|
|
612
|
+
}
|
|
613
|
+
const url = new URL(redirect_uri);
|
|
614
|
+
url.searchParams.set("code", code);
|
|
615
|
+
if (state) url.searchParams.set("state", state);
|
|
616
|
+
if (userJson) url.searchParams.set("user", userJson);
|
|
617
|
+
return c.redirect(url.toString(), 302);
|
|
618
|
+
});
|
|
619
|
+
app.post("/auth/token", async (c) => {
|
|
620
|
+
const rawText = await c.req.text();
|
|
621
|
+
const body = Object.fromEntries(new URLSearchParams(rawText));
|
|
622
|
+
const grant_type = body.grant_type ?? "";
|
|
623
|
+
const code = body.code ?? "";
|
|
624
|
+
const client_id = body.client_id ?? "";
|
|
625
|
+
const refresh_token = body.refresh_token ?? "";
|
|
626
|
+
if (grant_type === "authorization_code") {
|
|
627
|
+
const pendingMap = getPendingCodes(store);
|
|
628
|
+
const pending = pendingMap.get(code);
|
|
629
|
+
if (!pending) {
|
|
630
|
+
return c.json({ error: "invalid_grant", error_description: "The code is incorrect or expired." }, 400);
|
|
631
|
+
}
|
|
632
|
+
if (isPendingCodeExpired(pending)) {
|
|
633
|
+
pendingMap.delete(code);
|
|
634
|
+
return c.json({ error: "invalid_grant", error_description: "The code is incorrect or expired." }, 400);
|
|
635
|
+
}
|
|
636
|
+
pendingMap.delete(code);
|
|
637
|
+
const user = as.users.findOneBy("email", pending.email);
|
|
638
|
+
if (!user) {
|
|
639
|
+
return c.json({ error: "invalid_grant", error_description: "User not found." }, 400);
|
|
640
|
+
}
|
|
641
|
+
const accessToken = "apple_" + randomBytes2(20).toString("base64url");
|
|
642
|
+
const refreshToken = "r_apple_" + randomBytes2(20).toString("base64url");
|
|
643
|
+
const scopes = pending.scope ? pending.scope.split(/\s+/).filter(Boolean) : [];
|
|
644
|
+
if (tokenMap) {
|
|
645
|
+
tokenMap.set(accessToken, { login: user.email, id: user.id, scopes });
|
|
646
|
+
}
|
|
647
|
+
getRefreshTokens(store).set(refreshToken, {
|
|
648
|
+
email: user.email,
|
|
649
|
+
clientId: pending.clientId,
|
|
650
|
+
scope: pending.scope,
|
|
651
|
+
nonce: pending.nonce
|
|
652
|
+
});
|
|
653
|
+
const idToken = await createIdToken(user, pending.clientId, pending.nonce, baseUrl);
|
|
654
|
+
debug("apple.oauth", `[Apple token] issued token for ${user.email}`);
|
|
655
|
+
return c.json({
|
|
656
|
+
access_token: accessToken,
|
|
657
|
+
token_type: "Bearer",
|
|
658
|
+
expires_in: 3600,
|
|
659
|
+
refresh_token: refreshToken,
|
|
660
|
+
id_token: idToken
|
|
661
|
+
});
|
|
662
|
+
}
|
|
663
|
+
if (grant_type === "refresh_token") {
|
|
664
|
+
const refreshMap = getRefreshTokens(store);
|
|
665
|
+
const stored = refreshMap.get(refresh_token);
|
|
666
|
+
if (!stored) {
|
|
667
|
+
return c.json({ error: "invalid_grant", error_description: "The refresh_token is invalid." }, 400);
|
|
668
|
+
}
|
|
669
|
+
const user = as.users.findOneBy("email", stored.email);
|
|
670
|
+
if (!user) {
|
|
671
|
+
return c.json({ error: "invalid_grant", error_description: "User not found." }, 400);
|
|
672
|
+
}
|
|
673
|
+
const accessToken = "apple_" + randomBytes2(20).toString("base64url");
|
|
674
|
+
const scopes = stored.scope ? stored.scope.split(/\s+/).filter(Boolean) : [];
|
|
675
|
+
if (tokenMap) {
|
|
676
|
+
tokenMap.set(accessToken, { login: user.email, id: user.id, scopes });
|
|
677
|
+
}
|
|
678
|
+
const idToken = await createIdToken(user, stored.clientId || client_id, stored.nonce, baseUrl);
|
|
679
|
+
debug("apple.oauth", `[Apple refresh] issued new token for ${user.email}`);
|
|
680
|
+
return c.json({
|
|
681
|
+
access_token: accessToken,
|
|
682
|
+
token_type: "Bearer",
|
|
683
|
+
expires_in: 3600,
|
|
684
|
+
id_token: idToken
|
|
685
|
+
});
|
|
686
|
+
}
|
|
687
|
+
return c.json(
|
|
688
|
+
{
|
|
689
|
+
error: "unsupported_grant_type",
|
|
690
|
+
error_description: "Only authorization_code and refresh_token are supported."
|
|
691
|
+
},
|
|
692
|
+
400
|
|
693
|
+
);
|
|
694
|
+
});
|
|
695
|
+
app.post("/auth/revoke", async (c) => {
|
|
696
|
+
const rawText = await c.req.text();
|
|
697
|
+
const params = new URLSearchParams(rawText);
|
|
698
|
+
const token = params.get("token") ?? "";
|
|
699
|
+
if (token && tokenMap) {
|
|
700
|
+
tokenMap.delete(token);
|
|
701
|
+
}
|
|
702
|
+
if (token) {
|
|
703
|
+
getRefreshTokens(store).delete(token);
|
|
704
|
+
}
|
|
705
|
+
return c.body(null, 200);
|
|
706
|
+
});
|
|
707
|
+
}
|
|
708
|
+
var manifest = {
|
|
709
|
+
id: "apple",
|
|
710
|
+
name: "Apple Sign In / OAuth",
|
|
711
|
+
description: "Stateful Sign in with Apple emulator for OAuth authorization code and OpenID Connect flows.",
|
|
712
|
+
docsUrl: "https://docs.emulators.dev/apple",
|
|
713
|
+
surfaces: [
|
|
714
|
+
{ id: "oauth", kind: "oauth", title: "Sign in with Apple", status: "supported", basePath: "/auth" },
|
|
715
|
+
{ id: "oidc", kind: "oidc", title: "OpenID Connect", status: "supported", basePath: "/.well-known" }
|
|
716
|
+
],
|
|
717
|
+
auth: [
|
|
718
|
+
{ id: "oauth-code", title: "OAuth authorization code", type: "oauth-authorization-code", status: "supported" },
|
|
719
|
+
{ id: "oidc", title: "OIDC identity tokens", type: "oidc", status: "supported" }
|
|
720
|
+
],
|
|
721
|
+
specs: [
|
|
722
|
+
{
|
|
723
|
+
kind: "oauth-metadata",
|
|
724
|
+
title: "Apple OIDC metadata",
|
|
725
|
+
coverage: "hand-authored",
|
|
726
|
+
operations: [
|
|
727
|
+
{
|
|
728
|
+
operationId: "openid-configuration",
|
|
729
|
+
method: "GET",
|
|
730
|
+
path: "/.well-known/openid-configuration",
|
|
731
|
+
status: "hand-authored",
|
|
732
|
+
summary: "OIDC discovery document."
|
|
733
|
+
},
|
|
734
|
+
{
|
|
735
|
+
operationId: "jwks",
|
|
736
|
+
method: "GET",
|
|
737
|
+
path: "/auth/keys",
|
|
738
|
+
status: "hand-authored",
|
|
739
|
+
summary: "JWKS signing keys."
|
|
740
|
+
},
|
|
741
|
+
{
|
|
742
|
+
operationId: "authorize",
|
|
743
|
+
method: "GET",
|
|
744
|
+
path: "/auth/authorize",
|
|
745
|
+
status: "hand-authored",
|
|
746
|
+
summary: "Sign in with Apple authorization page."
|
|
747
|
+
},
|
|
748
|
+
{
|
|
749
|
+
operationId: "authorize-callback",
|
|
750
|
+
method: "POST",
|
|
751
|
+
path: "/auth/authorize/callback",
|
|
752
|
+
status: "hand-authored",
|
|
753
|
+
summary: "Issues an authorization code after user selection."
|
|
754
|
+
},
|
|
755
|
+
{
|
|
756
|
+
operationId: "token",
|
|
757
|
+
method: "POST",
|
|
758
|
+
path: "/auth/token",
|
|
759
|
+
status: "hand-authored",
|
|
760
|
+
summary: "Exchanges authorization codes and refresh tokens for access and id tokens."
|
|
761
|
+
},
|
|
762
|
+
{
|
|
763
|
+
operationId: "revoke",
|
|
764
|
+
method: "POST",
|
|
765
|
+
path: "/auth/revoke",
|
|
766
|
+
status: "hand-authored",
|
|
767
|
+
summary: "Revokes an access or refresh token."
|
|
768
|
+
}
|
|
769
|
+
]
|
|
770
|
+
}
|
|
771
|
+
],
|
|
772
|
+
seedSchema: {
|
|
773
|
+
description: "Seed Apple ID users and registered Sign in with Apple service clients.",
|
|
774
|
+
fields: [
|
|
775
|
+
{
|
|
776
|
+
key: "users",
|
|
777
|
+
title: "Users",
|
|
778
|
+
description: "Apple ID accounts addressable by email, optionally using private relay.",
|
|
779
|
+
example: [{ email: "testuser@icloud.com", name: "Test User", is_private_email: false }]
|
|
780
|
+
},
|
|
781
|
+
{
|
|
782
|
+
key: "oauth_clients",
|
|
783
|
+
title: "OAuth clients",
|
|
784
|
+
description: "Registered service IDs with team id and redirect URIs.",
|
|
785
|
+
example: [
|
|
786
|
+
{
|
|
787
|
+
client_id: "com.example.app",
|
|
788
|
+
team_id: "TEAM001",
|
|
789
|
+
name: "My Apple App",
|
|
790
|
+
redirect_uris: ["http://localhost:3000/api/auth/callback/apple"]
|
|
791
|
+
}
|
|
792
|
+
]
|
|
793
|
+
}
|
|
794
|
+
],
|
|
795
|
+
example: {
|
|
796
|
+
users: [{ email: "testuser@icloud.com", name: "Test User", is_private_email: false }],
|
|
797
|
+
oauth_clients: [
|
|
798
|
+
{
|
|
799
|
+
client_id: "com.example.app",
|
|
800
|
+
team_id: "TEAM001",
|
|
801
|
+
name: "My Apple App",
|
|
802
|
+
redirect_uris: ["http://localhost:3000/api/auth/callback/apple"]
|
|
803
|
+
}
|
|
804
|
+
]
|
|
805
|
+
}
|
|
806
|
+
},
|
|
807
|
+
stateModel: {
|
|
808
|
+
description: "Entities mutated by Apple Sign in with Apple flows.",
|
|
809
|
+
collections: [{ name: "apple.users" }, { name: "apple.oauth_clients" }]
|
|
810
|
+
},
|
|
811
|
+
connections: [
|
|
812
|
+
{
|
|
813
|
+
id: "openid-client",
|
|
814
|
+
title: "openid-client (TypeScript)",
|
|
815
|
+
kind: "sdk",
|
|
816
|
+
language: "typescript",
|
|
817
|
+
description: "Discover the emulator issuer and run the authorization code flow.",
|
|
818
|
+
template: 'import * as client from "openid-client";\n\nconst config = await client.discovery(\n new URL("{{baseUrl}}"),\n "{{clientId}}",\n "{{clientSecret}}",\n);'
|
|
819
|
+
},
|
|
820
|
+
{
|
|
821
|
+
id: "apple-env",
|
|
822
|
+
title: "Sign in with Apple (env)",
|
|
823
|
+
kind: "env",
|
|
824
|
+
language: "bash",
|
|
825
|
+
description: "Point your auth library at the emulator issuer and endpoints.",
|
|
826
|
+
template: "APPLE_ISSUER={{baseUrl}}\nAPPLE_AUTHORIZATION_URL={{baseUrl}}/auth/authorize\nAPPLE_TOKEN_URL={{baseUrl}}/auth/token\nAPPLE_JWKS_URL={{baseUrl}}/auth/keys\nAPPLE_CLIENT_ID={{clientId}}\nAPPLE_CLIENT_SECRET={{clientSecret}}"
|
|
827
|
+
},
|
|
828
|
+
{
|
|
829
|
+
id: "curl-discovery",
|
|
830
|
+
title: "curl OIDC discovery",
|
|
831
|
+
kind: "curl",
|
|
832
|
+
language: "bash",
|
|
833
|
+
description: "Fetch the OpenID Connect discovery document.",
|
|
834
|
+
template: "curl -s {{baseUrl}}/.well-known/openid-configuration"
|
|
835
|
+
},
|
|
836
|
+
{
|
|
837
|
+
id: "curl-token",
|
|
838
|
+
title: "curl token exchange",
|
|
839
|
+
kind: "curl",
|
|
840
|
+
language: "bash",
|
|
841
|
+
description: "Exchange an authorization code for tokens.",
|
|
842
|
+
template: 'curl -s -X POST {{baseUrl}}/auth/token \\\n -H "content-type: application/x-www-form-urlencoded" \\\n -d "grant_type=authorization_code&code=<code>&client_id={{clientId}}&client_secret={{clientSecret}}"'
|
|
843
|
+
}
|
|
844
|
+
]
|
|
845
|
+
};
|
|
846
|
+
function seedDefaults(store, _baseUrl) {
|
|
847
|
+
const as = getAppleStore(store);
|
|
848
|
+
as.users.insert({
|
|
849
|
+
uid: generateAppleUid(),
|
|
850
|
+
email: "testuser@icloud.com",
|
|
851
|
+
name: "Test User",
|
|
852
|
+
given_name: "Test",
|
|
853
|
+
family_name: "User",
|
|
854
|
+
email_verified: true,
|
|
855
|
+
is_private_email: false,
|
|
856
|
+
private_relay_email: null,
|
|
857
|
+
real_user_status: 2
|
|
858
|
+
});
|
|
859
|
+
}
|
|
860
|
+
function seedFromConfig(store, _baseUrl, config) {
|
|
861
|
+
const as = getAppleStore(store);
|
|
862
|
+
if (config.users) {
|
|
863
|
+
for (const u of config.users) {
|
|
864
|
+
const existing = as.users.findOneBy("email", u.email);
|
|
865
|
+
if (existing) continue;
|
|
866
|
+
const nameParts = (u.name ?? "").split(/\s+/);
|
|
867
|
+
const isPrivate = u.is_private_email ?? false;
|
|
868
|
+
as.users.insert({
|
|
869
|
+
uid: generateAppleUid(),
|
|
870
|
+
email: u.email,
|
|
871
|
+
name: u.name ?? u.email.split("@")[0],
|
|
872
|
+
given_name: u.given_name ?? nameParts[0] ?? "",
|
|
873
|
+
family_name: u.family_name ?? nameParts.slice(1).join(" ") ?? "",
|
|
874
|
+
email_verified: true,
|
|
875
|
+
is_private_email: isPrivate,
|
|
876
|
+
private_relay_email: isPrivate ? generatePrivateRelayEmail() : null,
|
|
877
|
+
real_user_status: 2
|
|
878
|
+
});
|
|
879
|
+
}
|
|
880
|
+
}
|
|
881
|
+
if (config.oauth_clients) {
|
|
882
|
+
for (const client of config.oauth_clients) {
|
|
883
|
+
const existing = as.oauthClients.findOneBy("client_id", client.client_id);
|
|
884
|
+
if (existing) continue;
|
|
885
|
+
as.oauthClients.insert({
|
|
886
|
+
client_id: client.client_id,
|
|
887
|
+
team_id: client.team_id,
|
|
888
|
+
key_id: client.key_id ?? "TESTKEY001",
|
|
889
|
+
name: client.name,
|
|
890
|
+
redirect_uris: client.redirect_uris
|
|
891
|
+
});
|
|
892
|
+
}
|
|
893
|
+
}
|
|
894
|
+
}
|
|
895
|
+
var applePlugin = {
|
|
896
|
+
name: "apple",
|
|
897
|
+
register(app, store, webhooks, baseUrl, tokenMap) {
|
|
898
|
+
const ctx = { app, store, webhooks, baseUrl, tokenMap };
|
|
899
|
+
oauthRoutes(ctx);
|
|
900
|
+
},
|
|
901
|
+
seed(store, baseUrl) {
|
|
902
|
+
seedDefaults(store, baseUrl);
|
|
903
|
+
}
|
|
904
|
+
};
|
|
905
|
+
var index_default = applePlugin;
|
|
906
|
+
export {
|
|
907
|
+
applePlugin,
|
|
908
|
+
index_default as default,
|
|
909
|
+
getAppleStore,
|
|
910
|
+
manifest,
|
|
911
|
+
seedFromConfig
|
|
912
|
+
};
|
|
913
|
+
//# sourceMappingURL=dist-ZEC77OKZ.js.map
|