Repository navigation
Expand file tree
/
Copy pathAuthAdminMFA.swift
More file actions
50 lines (45 loc) · 1.77 KB
/
Copy pathAuthAdminMFA.swift
File metadata and controls
50 lines (45 loc) · 1.77 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
//
// AuthAdminMFA.swift
//
//
// Created by Ranbir Singh on 16/09/26.
//
public import Foundation
/// Admin operations for managing a user's multi-factor authentication factors.
///
/// Access this namespace via ``AuthAdminClient/mfa``.
///
/// > Warning: These methods require the secret key. Never expose this key
/// > in a browser or mobile app. Call these methods from a secure server-side environment only.
///
/// ## Topics
///
/// ### Managing factors
/// - ``listFactors(forUser:)``
/// - ``deleteFactor(id:forUser:)``
public struct AuthAdminMFA: Sendable {
let admin: AuthAdminClient
var api: APIClient { admin.api }
var authAPI: AuthAPI { admin.authAPI }
/// Lists the MFA factors enrolled by a user.
///
/// - Parameter userID: The user's unique identifier.
/// - Returns: The user's factors.
/// - Throws: ``AuthError`` when the request fails. `CancellationError` when the task is
/// cancelled.
/// - Note: This function should only be called on a server. Never expose your `secret` key in the client.
public func listFactors(forUser userID: UUID) async throws -> [Factor] {
try await api.execute(authAPI.adminListFactors(userID: userID))
}
/// Deletes an MFA factor enrolled by a user, and downgrades that user's sessions to AAL1.
///
/// - Parameters:
/// - id: The identifier of the factor to delete, as found on ``Factor/id``.
/// - userID: The user's unique identifier.
/// - Throws: ``AuthError`` when the request fails. `CancellationError` when the task is
/// cancelled.
/// - Note: This function should only be called on a server. Never expose your `secret` key in the client.
public func deleteFactor(id: UUID, forUser userID: UUID) async throws {
try await api.execute(authAPI.adminDeleteFactor(id: id, userID: userID))
}
}