This repository was archived by the owner on Sep 15, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathSocialLogin2FANonceInfo.swift
More file actions
56 lines (51 loc) · 1.89 KB
/
SocialLogin2FANonceInfo.swift
File metadata and controls
56 lines (51 loc) · 1.89 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
import Foundation
@objc
/// This type is not only used for social logins, but we have not renamed it to maintain compatibility.
///
public class SocialLogin2FANonceInfo: NSObject {
@objc public var nonceSMS = ""
@objc public var nonceWebauthn = ""
@objc var nonceBackup = ""
@objc var nonceAuthenticator = ""
@objc var supportedAuthTypes = [String]() // backup|authenticator|sms|webauthn
@objc var notificationSent = "" // none|sms
@objc var phoneNumber = "" // The last two digits of the phone number to which an SMS was sent.
private enum Constants {
static let lastUsedPlaceholder = "last_used_placeholder"
}
/// These constants match the server-side authentication code
public enum TwoFactorTypeLengths: Int {
case authenticator = 6
case sms = 7
case backup = 8
}
public func authTypeAndNonce(for code: String) -> (String, String) {
let typeNoncePair: (String, String)
switch code.count {
case TwoFactorTypeLengths.sms.rawValue:
typeNoncePair = ("sms", nonceSMS)
nonceSMS = Constants.lastUsedPlaceholder
case TwoFactorTypeLengths.backup.rawValue:
typeNoncePair = ("backup", nonceBackup)
nonceBackup = Constants.lastUsedPlaceholder
case TwoFactorTypeLengths.authenticator.rawValue:
fallthrough
default:
typeNoncePair = ("authenticator", nonceAuthenticator)
nonceAuthenticator = Constants.lastUsedPlaceholder
}
return typeNoncePair
}
@objc public func updateNonce(with newNonce: String) {
switch Constants.lastUsedPlaceholder {
case nonceSMS:
nonceSMS = newNonce
case nonceBackup:
nonceBackup = newNonce
case nonceAuthenticator:
fallthrough
default:
nonceAuthenticator = newNonce
}
}
}