-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathConfirmRecoveryCodeEnrollmentUseCase.swift
More file actions
67 lines (62 loc) · 2.76 KB
/
Copy pathConfirmRecoveryCodeEnrollmentUseCase.swift
File metadata and controls
67 lines (62 loc) · 2.76 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
import Auth0
import Foundation
import Combine
/// Protocol for the recovery code enrollment confirmation use case.
protocol ConfirmRecoveryCodeEnrollmentUseCaseable {
/// The URLSession used for network requests
var session: URLSession { get }
/// Confirms recovery code enrollment.
///
/// - Parameter request: The request containing enrollment details
/// - Returns: The created authentication method
/// - Throws: Auth0 or network errors if the operation fails
func execute(request: ConfirmRecoveryCodeEnrollmentRequest) async throws -> AuthenticationMethod
}
/// Request model for confirming recovery code enrollment.
///
/// Contains the enrollment session information needed to complete
/// the recovery code enrollment process.
///
/// ## See Also
///
/// - [Recovery Codes]
/// (https://auth0.com/docs/secure/multi-factor-authentication/multi-factor-authentication-factors#recovery-codes)
/// - [My Account API](https://auth0.com/docs/manage-users/my-account-api)
struct ConfirmRecoveryCodeEnrollmentRequest {
/// Access token for authenticating with Auth0's My Account API
let token: String
/// Auth0 tenant domain (e.g., "example.auth0.com")
let domain: String
/// The enrollment ID from the initial challenge. This uniquely identifies the authentication
/// method being enrolled.
let id: String
/// The authentication session identifier from the challenge. Used to maintain session state
/// during the enrollment flow.
let authSession: String
}
/// Use case for confirming recovery code enrollment.
///
/// Completes the recovery code enrollment process by confirming the
/// enrollment session. Upon successful confirmation, the recovery codes
/// can be used to access the account if other authentication methods fail.
struct ConfirmRecoveryCodeEnrollmentUseCase: ConfirmRecoveryCodeEnrollmentUseCaseable {
/// The URLSession used for network requests
var session: URLSession
/// Initializes the use case with an optional URLSession.
///
/// - Parameter session: The URLSession to use for requests (defaults to .shared)
init(session: URLSession = .shared) {
self.session = session
}
/// Confirms recovery code enrollment.
///
/// - Parameter request: Request containing enrollment details
/// - Returns: The newly created recovery code authentication method
/// - Throws: Auth0APIError if the request fails
func execute(request: ConfirmRecoveryCodeEnrollmentRequest) async throws -> AuthenticationMethod {
try await MyAccountClientFactory.create(token: request.token, domain: request.domain, session: session)
.authenticationMethods
.confirmRecoveryCodeEnrollment(id: request.id, authSession: request.authSession)
.start()
}
}