-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathGetFactorsUseCase.swift
More file actions
53 lines (48 loc) · 2.03 KB
/
Copy pathGetFactorsUseCase.swift
File metadata and controls
53 lines (48 loc) · 2.03 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
import Foundation
import Auth0
/// Request model for fetching authentication factors.
///
/// Contains the authentication token and Auth0 domain required to retrieve
/// the available authentication factors for the user's account.
struct GetFactorsRequest {
/// Access token for authenticating with Auth0's My Account API
let token: String
/// Auth0 tenant domain (e.g., "example.auth0.com")
let domain: String
}
/// Protocol for the authentication factors retrieval use case.
protocol GetFactorsUseCaseable {
/// The URLSession used for network requests
var session: URLSession { get }
/// Fetches all available authentication factors for the current user.
///
/// - Parameter request: The request containing token and domain
/// - Returns: An array of available authentication factors
/// - Throws: Auth0 or network errors if the operation fails
func execute(request: GetFactorsRequest) async throws -> [Factor]
}
/// Use case for retrieving authentication factors.
///
/// Fetches the list of available authentication factors that can be used
/// for additional authentication or recovery from the user's account.
struct GetFactorsUseCase: GetFactorsUseCaseable {
/// 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 = URLSession.shared) {
self.session = session
}
/// Fetches all authentication factors for the current user.
///
/// - Parameter request: Request containing authentication token and domain
/// - Returns: Array of available authentication factors
/// - Throws: Auth0APIError if the request fails
func execute(request: GetFactorsRequest) async throws -> [Factor] {
try await MyAccountClientFactory.create(token: request.token, domain: request.domain, session: session)
.authenticationMethods
.getFactors()
.start()
}
}