Skip to content

Commit 5e74e23

Browse files
committed
more refactoring
1 parent fbf9a38 commit 5e74e23

File tree

1 file changed

+27
-32
lines changed

1 file changed

+27
-32
lines changed

FirebaseAuth/Sources/Swift/Utilities/AuthRecaptchaVerifier.swift

Lines changed: 27 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -69,41 +69,12 @@ enum AuthRecaptchaAction: String {
6969

7070
@available(iOS 13, *)
7171
class AuthRecaptchaVerifier {
72+
private let recaptchaVersion = "RECAPTCHA_ENTERPRISE"
7273
weak var auth: Auth?
7374
private var agentConfig: AuthRecaptchaConfig?
7475
private var tenantConfigs: [String: AuthRecaptchaConfig] = [:]
7576
#if os(iOS)
7677
private var recaptchaClient: RCARecaptchaClientProtocol?
77-
#endif // os(iOS)
78-
private let recaptchaVersion = "RECAPTCHA_ENTERPRISE"
79-
}
80-
81-
#if os(iOS)
82-
@available(iOS 13, *)
83-
extension AuthRecaptchaVerifier {
84-
private func siteKey() -> String? {
85-
if let tenantID = auth?.tenantID {
86-
if let config = tenantConfigs[tenantID] {
87-
return config.siteKey
88-
}
89-
return nil
90-
}
91-
return agentConfig?.siteKey
92-
}
93-
94-
func enablementStatus(forProvider provider: AuthRecaptchaProvider)
95-
-> AuthRecaptchaEnablementStatus {
96-
if let tenantID = auth?.tenantID,
97-
let tenantConfig = tenantConfigs[tenantID],
98-
let status = tenantConfig.enablementStatus[provider] {
99-
return status
100-
} else if let agentConfig = agentConfig,
101-
let status = agentConfig.enablementStatus[provider] {
102-
return status
103-
} else {
104-
return AuthRecaptchaEnablementStatus.off
105-
}
106-
}
10778

10879
func verify(forceRefresh: Bool, action: AuthRecaptchaAction) async throws -> String {
10980
try await retrieveRecaptchaConfig(forceRefresh: forceRefresh)
@@ -143,6 +114,30 @@ class AuthRecaptchaVerifier {
143114
#endif // !(COCOAPODS || SWIFT_PACKAGE)
144115
}
145116

117+
private func siteKey() -> String? {
118+
if let tenantID = auth?.tenantID {
119+
if let config = tenantConfigs[tenantID] {
120+
return config.siteKey
121+
}
122+
return nil
123+
}
124+
return agentConfig?.siteKey
125+
}
126+
127+
func enablementStatus(forProvider provider: AuthRecaptchaProvider)
128+
-> AuthRecaptchaEnablementStatus {
129+
if let tenantID = auth?.tenantID,
130+
let tenantConfig = tenantConfigs[tenantID],
131+
let status = tenantConfig.enablementStatus[provider] {
132+
return status
133+
} else if let agentConfig = agentConfig,
134+
let status = agentConfig.enablementStatus[provider] {
135+
return status
136+
} else {
137+
return AuthRecaptchaEnablementStatus.off
138+
}
139+
}
140+
146141
private func recaptchaToken(siteKey: String,
147142
actionString: String,
148143
fakeToken: String) async -> (token: String, error: Error?,
@@ -262,5 +257,5 @@ class AuthRecaptchaVerifier {
262257
request.injectRecaptchaFields(recaptchaResponse: nil, recaptchaVersion: recaptchaVersion)
263258
}
264259
}
265-
}
266-
#endif // os(iOS)
260+
#endif // os(iOS)
261+
}

0 commit comments

Comments
 (0)