-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathHooks+Passkey.swift
More file actions
300 lines (246 loc) · 10.1 KB
/
Copy pathHooks+Passkey.swift
File metadata and controls
300 lines (246 loc) · 10.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
public import Vapor
public extension Passage.Hooks {
protocol Passkey: Sendable {
// MARK: Guest Registration Hooks
func willBeginGuestRegistration(
with form: any PasskeyGuestRegistrationForm,
as entity: PublicKeyCredentialUserEntity,
on request: Request,
) async throws
func didBeginGuestRegistration(
with result: PasskeyBeginResult,
on request: Request,
) async
func willFinishGuestRegistration(
with identifier: Identifier?,
on request: Request,
) async throws
func didFinishGuestRegistration(
with credential: StoredPasskeyCredential,
for user: any User,
on request: Request,
) async
// MARK: Registration Hooks
func willBeginRegistration(
for user: any User,
as entity: PublicKeyCredentialUserEntity,
on request: Request
) async throws
func didBeginRegistration(
with result: PasskeyBeginResult,
for user: any User,
on request: Request
) async
func willFinishRegistration(
for user: (any User)?,
on request: Request,
) async throws
func didFinishRegistration(
with credential: StoredPasskeyCredential,
for user: any User,
on request: Request,
) async
// MARK: Authentication Hooks
func willBeginAuthentication(
on request: Request,
) async throws
func didBeginAuthentication(
with result: PasskeyBeginResult,
on request: Request,
) async
func willFinishAuthentication(
with credential: StoredPasskeyCredential,
for user: any User,
on request: Request,
) async throws
func didFinishAuthentication(
with credential: StoredPasskeyCredential,
for user: any User,
code: String,
on request: Request,
) async
}
}
// MARK: - Default Implementation
public extension Passage.Hooks.Passkey {
func willBeginGuestRegistration(
with form: any PasskeyGuestRegistrationForm,
as entity: PublicKeyCredentialUserEntity,
on request: Request,
) async throws {}
func didBeginGuestRegistration(
with result: PasskeyBeginResult,
on request: Request,
) async {}
func willFinishGuestRegistration(
with identifier: Identifier?,
on request: Request,
) async throws {}
func didFinishGuestRegistration(
with credential: StoredPasskeyCredential,
for user: any User,
on request: Request,
) async {}
func willBeginRegistration(
for user: any User,
as entity: PublicKeyCredentialUserEntity,
on request: Request
) async throws {}
func didBeginRegistration(
with result: PasskeyBeginResult,
for user: any User,
on request: Request
) async {}
func willFinishRegistration(
for user: (any User)?,
on request: Request,
) async throws {}
func didFinishRegistration(
with credential: StoredPasskeyCredential,
for user: any User,
on request: Request,
) async {}
func willBeginAuthentication(
on request: Request,
) async throws {}
func didBeginAuthentication(
with result: PasskeyBeginResult,
on request: Request,
) async {}
func willFinishAuthentication(
with credential: StoredPasskeyCredential,
for user: any User,
on request: Request,
) async throws {}
func didFinishAuthentication(
with credential: StoredPasskeyCredential,
for user: any User,
code: String,
on request: Request,
) async {}
}
// MARK: - Closure-Based Hooks
public struct _PasskeyHooksClosures: Passage.Hooks.Passkey {
let _willBeginGuestRegistration: (@Sendable (any PasskeyGuestRegistrationForm, PublicKeyCredentialUserEntity, Request) async throws -> Void)?
let _didBeginGuestRegistration: (@Sendable (PasskeyBeginResult, Request) async -> Void)?
let _willFinishGuestRegistration: (@Sendable (Identifier?, Request) async throws -> Void)?
let _didFinishGuestRegistration: (@Sendable (StoredPasskeyCredential, any User, Request) async -> Void)?
let _willBeginRegistration: (@Sendable (any User, PublicKeyCredentialUserEntity, Request) async throws -> Void)?
let _didBeginRegistration: (@Sendable (PasskeyBeginResult, any User, Request) async -> Void)?
let _willFinishRegistration: (@Sendable ((any User)?, Request) async throws -> Void)?
let _didFinishRegistration: (@Sendable (StoredPasskeyCredential, any User, Request) async -> Void)?
let _willBeginAuthentication: (@Sendable (Request) async throws -> Void)?
let _didBeginAuthentication: (@Sendable (PasskeyBeginResult, Request) async -> Void)?
let _willFinishAuthentication: (@Sendable (StoredPasskeyCredential, any User, Request) async throws -> Void)?
let _didFinishAuthentication: (@Sendable (StoredPasskeyCredential, any User, String, Request) async -> Void)?
public func willBeginGuestRegistration(
with form: any PasskeyGuestRegistrationForm,
as entity: PublicKeyCredentialUserEntity,
on request: Request,
) async throws {
try await _willBeginGuestRegistration?(form, entity, request)
}
public func didBeginGuestRegistration(
with result: PasskeyBeginResult,
on request: Request,
) async {
await _didBeginGuestRegistration?(result, request)
}
public func willFinishGuestRegistration(
with identifier: Identifier?,
on request: Request,
) async throws {
try await _willFinishGuestRegistration?(identifier, request)
}
public func didFinishGuestRegistration(
with credential: StoredPasskeyCredential,
for user: any User,
on request: Request,
) async {
await _didFinishGuestRegistration?(credential, user, request)
}
public func willBeginRegistration(
for user: any User,
as entity: PublicKeyCredentialUserEntity,
on request: Request
) async throws {
try await _willBeginRegistration?(user, entity, request)
}
public func didBeginRegistration(
with result: PasskeyBeginResult,
for user: any User,
on request: Request
) async {
try await _didBeginRegistration?(result, user, request)
}
public func willFinishRegistration(
for user: (any User)?,
on request: Request,
) async throws {
try await _willFinishRegistration?(user, request)
}
public func didFinishRegistration(
with credential: StoredPasskeyCredential,
for user: any User,
on request: Request,
) async {
try await _didFinishRegistration?(credential, user, request)
}
public func willBeginAuthentication(
on request: Request,
) async throws {
try await _willBeginAuthentication?(request)
}
public func didBeginAuthentication(
with result: PasskeyBeginResult,
on request: Request,
) async {
await _didBeginAuthentication?(result, request)
}
public func willFinishAuthentication(
with credential: StoredPasskeyCredential,
for user: any User,
on request: Request,
) async throws {
try await _willFinishAuthentication?(credential, user, request)
}
public func didFinishAuthentication(
with credential: StoredPasskeyCredential,
for user: any User,
code: String,
on request: Request,
) async {
await _didFinishAuthentication?(credential, user, code, request)
}
}
public extension Passage.Hooks.Passkey where Self == _PasskeyHooksClosures {
static func hook(
willBeginGuestRegistration : (@Sendable (any PasskeyGuestRegistrationForm, PublicKeyCredentialUserEntity, Request) async throws -> Void)? = nil,
didBeginGuestRegistration : (@Sendable (PasskeyBeginResult, Request) async -> Void)? = nil,
willFinishGuestRegistration : (@Sendable (Identifier?, Request) async throws -> Void)? = nil,
didFinishGuestRegistration : (@Sendable (StoredPasskeyCredential, any User, Request) async -> Void)? = nil,
willBeginRegistration : (@Sendable (any User, PublicKeyCredentialUserEntity, Request) async throws -> Void)? = nil,
didBeginRegistration : (@Sendable (PasskeyBeginResult, any User, Request) async -> Void)? = nil,
willFinishRegistration : (@Sendable ((any User)?, Request) async throws -> Void)? = nil,
didFinishRegistration : (@Sendable (StoredPasskeyCredential, any User, Request) async -> Void)? = nil,
willBeginAuthentication : (@Sendable (Request) async throws -> Void)? = nil,
didBeginAuthentication : (@Sendable (PasskeyBeginResult, Request) async -> Void)? = nil,
willFinishAuthentication : (@Sendable (StoredPasskeyCredential, any User, Request) async throws -> Void)? = nil,
didFinishAuthentication : (@Sendable (StoredPasskeyCredential, any User, String, Request) async -> Void)? = nil,
) -> some Passage.Hooks.Passkey {
_PasskeyHooksClosures(
_willBeginGuestRegistration : willBeginGuestRegistration,
_didBeginGuestRegistration : didBeginGuestRegistration,
_willFinishGuestRegistration: willFinishGuestRegistration,
_didFinishGuestRegistration : didFinishGuestRegistration,
_willBeginRegistration : willBeginRegistration,
_didBeginRegistration : didBeginRegistration,
_willFinishRegistration : willFinishRegistration,
_didFinishRegistration : didFinishRegistration,
_willBeginAuthentication : willBeginAuthentication,
_didBeginAuthentication : didBeginAuthentication,
_willFinishAuthentication : willFinishAuthentication,
_didFinishAuthentication : didFinishAuthentication
)
}
}