-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathStartRecoveryCodeEnrollmentUseCase.swift
More file actions
54 lines (49 loc) · 2.28 KB
/
Copy pathStartRecoveryCodeEnrollmentUseCase.swift
File metadata and controls
54 lines (49 loc) · 2.28 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
import Auth0
import Foundation
/// Protocol for the recovery code enrollment initiation use case.
protocol StartRecoveryCodeEnrollmentUseCaseable {
/// The URLSession used for network requests
var session: URLSession { get }
/// Initiates recovery code enrollment and returns the enrollment challenge.
///
/// - Parameter request: The request containing token and domain
/// - Returns: A RecoveryCodeEnrollmentChallenge with the recovery codes
/// - Throws: Auth0 or network errors if the operation fails
func execute(request: StartRecoveryCodeEnrollmentRequest) async throws -> RecoveryCodeEnrollmentChallenge
}
/// Request model for initiating recovery code enrollment.
///
/// Contains the authentication token and Auth0 domain required to generate
/// recovery codes for account recovery.
struct StartRecoveryCodeEnrollmentRequest {
/// Access token for authenticating with Auth0's My Account API
let token: String
/// Auth0 tenant domain (e.g., "example.auth0.com")
let domain: String
}
/// Use case for starting recovery code enrollment.
///
/// Initiates recovery code generation by requesting a challenge from Auth0's
/// My Account API. Recovery codes are backup codes that can be used to access
/// the account if other authentication methods are not available.
struct StartRecoveryCodeEnrollmentUseCase: StartRecoveryCodeEnrollmentUseCaseable {
/// 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
}
/// Starts recovery code enrollment and returns the recovery codes.
///
/// - Parameter request: Request containing authentication token and domain
/// - Returns: Recovery code enrollment challenge with generated codes
/// - Throws: Auth0APIError if the request fails
func execute(request: StartRecoveryCodeEnrollmentRequest) async throws -> RecoveryCodeEnrollmentChallenge {
try await MyAccountClientFactory.create(token: request.token, domain: request.domain, session: session)
.authenticationMethods
.enrollRecoveryCode()
.start()
}
}