Skip to content

Commit

Permalink
Fix platform build failures
Browse files Browse the repository at this point in the history
  • Loading branch information
ncooke3 committed Dec 10, 2024
1 parent ea122b7 commit e0f9336
Showing 1 changed file with 92 additions and 86 deletions.
178 changes: 92 additions & 86 deletions FirebaseAuth/Sources/Swift/Utilities/AuthRecaptchaVerifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,69 +12,113 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#if os(iOS)
import Foundation

import Foundation
#if SWIFT_PACKAGE
import FirebaseAuthInternal
#endif

#if SWIFT_PACKAGE
import FirebaseAuthInternal
#endif
#if os(iOS)
import RecaptchaInterop
#endif

@available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
class AuthRecaptchaConfig {
var siteKey: String?
let enablementStatus: [AuthRecaptchaProvider: AuthRecaptchaEnablementStatus]
@available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
class AuthRecaptchaConfig {
var siteKey: String?
let enablementStatus: [AuthRecaptchaProvider: AuthRecaptchaEnablementStatus]

init(siteKey: String? = nil,
enablementStatus: [AuthRecaptchaProvider: AuthRecaptchaEnablementStatus]) {
self.siteKey = siteKey
self.enablementStatus = enablementStatus
}
init(siteKey: String? = nil,
enablementStatus: [AuthRecaptchaProvider: AuthRecaptchaEnablementStatus]) {
self.siteKey = siteKey
self.enablementStatus = enablementStatus
}
}

@available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
enum AuthRecaptchaEnablementStatus: String, CaseIterable {
case enforce = "ENFORCE"
case audit = "AUDIT"
case off = "OFF"
@available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
enum AuthRecaptchaEnablementStatus: String, CaseIterable {
case enforce = "ENFORCE"
case audit = "AUDIT"
case off = "OFF"

// Convenience property for mapping values
var stringValue: String { rawValue }
}
// Convenience property for mapping values
var stringValue: String { rawValue }
}

@available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
enum AuthRecaptchaProvider: String, CaseIterable {
case password = "EMAIL_PASSWORD_PROVIDER"
case phone = "PHONE_PROVIDER"
@available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
enum AuthRecaptchaProvider: String, CaseIterable {
case password = "EMAIL_PASSWORD_PROVIDER"
case phone = "PHONE_PROVIDER"

// Convenience property for mapping values
var stringValue: String { rawValue }
}
// Convenience property for mapping values
var stringValue: String { rawValue }
}

@available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
enum AuthRecaptchaAction: String {
case defaultAction
case signInWithPassword
case getOobCode
case signUpPassword
case sendVerificationCode
case mfaSmsSignIn
case mfaSmsEnrollment
@available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
enum AuthRecaptchaAction: String {
case defaultAction
case signInWithPassword
case getOobCode
case signUpPassword
case sendVerificationCode
case mfaSmsSignIn
case mfaSmsEnrollment

// Convenience property for mapping values
var stringValue: String { rawValue }
}

@available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
class AuthRecaptchaVerifier {
weak var auth: Auth?
private var agentConfig: AuthRecaptchaConfig?
private var tenantConfigs: [String: AuthRecaptchaConfig] = [:]
private var recaptchaClient: RCARecaptchaClientProtocol?

Check failure on line 75 in FirebaseAuth/Sources/Swift/Utilities/AuthRecaptchaVerifier.swift

View workflow job for this annotation

GitHub Actions / spm (macos-15, Xcode_16, visionOS spm)

cannot find type 'RCARecaptchaClientProtocol' in scope

Check failure on line 75 in FirebaseAuth/Sources/Swift/Utilities/AuthRecaptchaVerifier.swift

View workflow job for this annotation

GitHub Actions / spm (macos-15, Xcode_16, visionOS spm)

cannot find type 'RCARecaptchaClientProtocol' in scope

Check failure on line 75 in FirebaseAuth/Sources/Swift/Utilities/AuthRecaptchaVerifier.swift

View workflow job for this annotation

GitHub Actions / spm (macos-15, Xcode_16, macOS spmbuildonly)

cannot find type 'RCARecaptchaClientProtocol' in scope

Check failure on line 75 in FirebaseAuth/Sources/Swift/Utilities/AuthRecaptchaVerifier.swift

View workflow job for this annotation

GitHub Actions / spm (macos-15, Xcode_16, macOS spmbuildonly)

cannot find type 'RCARecaptchaClientProtocol' in scope

Check failure on line 75 in FirebaseAuth/Sources/Swift/Utilities/AuthRecaptchaVerifier.swift

View workflow job for this annotation

GitHub Actions / spm (macos-15, Xcode_16, macOS spmbuildonly)

cannot find type 'RCARecaptchaClientProtocol' in scope

Check failure on line 75 in FirebaseAuth/Sources/Swift/Utilities/AuthRecaptchaVerifier.swift

View workflow job for this annotation

GitHub Actions / spm (macos-15, Xcode_16, macOS spmbuildonly)

cannot find type 'RCARecaptchaClientProtocol' in scope

Check failure on line 75 in FirebaseAuth/Sources/Swift/Utilities/AuthRecaptchaVerifier.swift

View workflow job for this annotation

GitHub Actions / spm (macos-15, Xcode_16, macOS spmbuildonly)

cannot find type 'RCARecaptchaClientProtocol' in scope

Check failure on line 75 in FirebaseAuth/Sources/Swift/Utilities/AuthRecaptchaVerifier.swift

View workflow job for this annotation

GitHub Actions / spm (macos-15, Xcode_16, macOS spmbuildonly)

cannot find type 'RCARecaptchaClientProtocol' in scope

Check failure on line 75 in FirebaseAuth/Sources/Swift/Utilities/AuthRecaptchaVerifier.swift

View workflow job for this annotation

GitHub Actions / spm (macos-15, Xcode_16, watchOS spm)

cannot find type 'RCARecaptchaClientProtocol' in scope

Check failure on line 75 in FirebaseAuth/Sources/Swift/Utilities/AuthRecaptchaVerifier.swift

View workflow job for this annotation

GitHub Actions / spm (macos-15, Xcode_16, watchOS spm)

cannot find type 'RCARecaptchaClientProtocol' in scope

Check failure on line 75 in FirebaseAuth/Sources/Swift/Utilities/AuthRecaptchaVerifier.swift

View workflow job for this annotation

GitHub Actions / spm (macos-15, Xcode_16, tvOS spm)

cannot find type 'RCARecaptchaClientProtocol' in scope

Check failure on line 75 in FirebaseAuth/Sources/Swift/Utilities/AuthRecaptchaVerifier.swift

View workflow job for this annotation

GitHub Actions / spm (macos-15, Xcode_16, tvOS spm)

cannot find type 'RCARecaptchaClientProtocol' in scope

Check failure on line 75 in FirebaseAuth/Sources/Swift/Utilities/AuthRecaptchaVerifier.swift

View workflow job for this annotation

GitHub Actions / spm (macos-15, Xcode_16, tvOS spm)

cannot find type 'RCARecaptchaClientProtocol' in scope

Check failure on line 75 in FirebaseAuth/Sources/Swift/Utilities/AuthRecaptchaVerifier.swift

View workflow job for this annotation

GitHub Actions / spm (macos-15, Xcode_16, tvOS spm)

cannot find type 'RCARecaptchaClientProtocol' in scope

Check failure on line 75 in FirebaseAuth/Sources/Swift/Utilities/AuthRecaptchaVerifier.swift

View workflow job for this annotation

GitHub Actions / spm (macos-15, Xcode_16, tvOS spm)

cannot find type 'RCARecaptchaClientProtocol' in scope

Check failure on line 75 in FirebaseAuth/Sources/Swift/Utilities/AuthRecaptchaVerifier.swift

View workflow job for this annotation

GitHub Actions / spm (macos-15, Xcode_16, tvOS spm)

cannot find type 'RCARecaptchaClientProtocol' in scope
private let kRecaptchaVersion = "RECAPTCHA_ENTERPRISE"

init() {}

// Convenience property for mapping values
var stringValue: String { rawValue }
func verify(forceRefresh: Bool, action: AuthRecaptchaAction) async throws -> String {
try await retrieveRecaptchaConfig(forceRefresh: forceRefresh)

Check failure on line 81 in FirebaseAuth/Sources/Swift/Utilities/AuthRecaptchaVerifier.swift

View workflow job for this annotation

GitHub Actions / spm (macos-15, Xcode_16, tvOS spm)

cannot find 'retrieveRecaptchaConfig' in scope

Check failure on line 81 in FirebaseAuth/Sources/Swift/Utilities/AuthRecaptchaVerifier.swift

View workflow job for this annotation

GitHub Actions / spm (macos-15, Xcode_16, tvOS spm)

cannot find 'retrieveRecaptchaConfig' in scope
guard let siteKey = siteKey() else {

Check failure on line 82 in FirebaseAuth/Sources/Swift/Utilities/AuthRecaptchaVerifier.swift

View workflow job for this annotation

GitHub Actions / spm (macos-15, Xcode_16, tvOS spm)

cannot find 'siteKey' in scope
throw AuthErrorUtils.recaptchaSiteKeyMissing()
}
let actionString = action.stringValue
#if !(COCOAPODS || SWIFT_PACKAGE)
// No recaptcha on internal build system.
return actionString
#else
let (token, error, linked, actionCreated) = await recaptchaToken(

Check failure on line 90 in FirebaseAuth/Sources/Swift/Utilities/AuthRecaptchaVerifier.swift

View workflow job for this annotation

GitHub Actions / spm (macos-15, Xcode_16, tvOS spm)

cannot find 'recaptchaToken' in scope
siteKey: siteKey,
actionString: actionString,
fakeToken: "NO_RECAPTCHA"
)

guard linked else {
throw AuthErrorUtils.recaptchaSDKNotLinkedError()
}
guard actionCreated else {
throw AuthErrorUtils.recaptchaActionCreationFailed()
}
if let error {
throw error
}
if token == "NO_RECAPTCHA" {
AuthLog.logInfo(code: "I-AUT000031",
message: "reCAPTCHA token retrieval failed. NO_RECAPTCHA sent as the fake code.")
} else {
AuthLog.logInfo(
code: "I-AUT000030",
message: "reCAPTCHA token retrieval succeeded."
)
}
return token
#endif // !(COCOAPODS || SWIFT_PACKAGE)
}
}

#if os(iOS)
@available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
class AuthRecaptchaVerifier {
weak var auth: Auth?
private var agentConfig: AuthRecaptchaConfig?
private var tenantConfigs: [String: AuthRecaptchaConfig] = [:]
private var recaptchaClient: RCARecaptchaClientProtocol?
private let kRecaptchaVersion = "RECAPTCHA_ENTERPRISE"
init() {}

extension AuthRecaptchaVerifier {
func siteKey() -> String? {
if let tenantID = auth?.tenantID {
if let config = tenantConfigs[tenantID] {
Expand All @@ -99,44 +143,6 @@
}
}

func verify(forceRefresh: Bool, action: AuthRecaptchaAction) async throws -> String {
try await retrieveRecaptchaConfig(forceRefresh: forceRefresh)
guard let siteKey = siteKey() else {
throw AuthErrorUtils.recaptchaSiteKeyMissing()
}
let actionString = action.stringValue
#if !(COCOAPODS || SWIFT_PACKAGE)
// No recaptcha on internal build system.
return actionString
#else
let (token, error, linked, actionCreated) = await recaptchaToken(
siteKey: siteKey,
actionString: actionString,
fakeToken: "NO_RECAPTCHA"
)

guard linked else {
throw AuthErrorUtils.recaptchaSDKNotLinkedError()
}
guard actionCreated else {
throw AuthErrorUtils.recaptchaActionCreationFailed()
}
if let error {
throw error
}
if token == "NO_RECAPTCHA" {
AuthLog.logInfo(code: "I-AUT000031",
message: "reCAPTCHA token retrieval failed. NO_RECAPTCHA sent as the fake code.")
} else {
AuthLog.logInfo(
code: "I-AUT000030",
message: "reCAPTCHA token retrieval succeeded."
)
}
return token
#endif // !(COCOAPODS || SWIFT_PACKAGE)
}

private func recaptchaToken(siteKey: String,
actionString: String,
fakeToken: String) async -> (token: String, error: Error?,
Expand Down

0 comments on commit e0f9336

Please sign in to comment.