Skip to content

Commit c2cae76

Browse files
Use AppCheckInterop APIs (#39)
1 parent ee60483 commit c2cae76

File tree

3 files changed

+12
-17
lines changed

3 files changed

+12
-17
lines changed

Package.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,10 @@ let package = Package(
4545
dependencies: [
4646
.product(name: "GRPC", package: "grpc-swift"),
4747
.product(name: "FirebaseCore", package: "firebase-ios-sdk"),
48-
// TODO: Investigate switching Auth and AppCheck to interop.
48+
49+
// TODO: Add FirebaseAppCheckInterop as a dependency once its available as an external library
50+
// TODO: Investigate switching Auth to interop.
4951
.product(name: "FirebaseAuth", package: "firebase-ios-sdk"),
50-
.product(name: "FirebaseAppCheck", package: "firebase-ios-sdk"),
5152
.product(name: "GULEnvironment", package: "GoogleUtilities"),
5253
],
5354
path: "Sources"

Sources/DataConnect.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
import Foundation
1616

17-
@preconcurrency import FirebaseAppCheck
1817
@preconcurrency import FirebaseAuth
1918
@preconcurrency import FirebaseCore
2019

Sources/Internal/GrpcClient.swift

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@
1414

1515
import Foundation
1616

17-
@preconcurrency import FirebaseAppCheck
17+
@preconcurrency import FirebaseAppCheckInterop
1818
@preconcurrency import FirebaseAuth
1919
import FirebaseCore
20+
@preconcurrency import FirebaseCoreExtension
2021
import GRPC
2122
import Logging
2223
import NIOCore
@@ -47,7 +48,7 @@ actor GrpcClient: CustomStringConvertible {
4748

4849
private let auth: Auth
4950

50-
private let appCheck: AppCheck?
51+
private let appCheck: AppCheckInterop?
5152

5253
private let callerSDKType: CallerSDKType
5354

@@ -108,7 +109,7 @@ actor GrpcClient: CustomStringConvertible {
108109
serverSettings = settings
109110
self.connectorConfig = connectorConfig
110111
auth = Auth.auth(app: app)
111-
appCheck = AppCheck.appCheck(app: app)
112+
appCheck = ComponentType<AppCheckInterop>.instance(for: AppCheckInterop.self, in: app.container)
112113
self.callerSDKType = callerSDKType
113114

114115
connectorName =
@@ -258,17 +259,11 @@ actor GrpcClient: CustomStringConvertible {
258259
}
259260

260261
// Add AppCheck token if available
261-
do {
262-
if let token = try await appCheck?.token(forcingRefresh: false) {
263-
headers.add(name: RequestHeaders.appCheckHeader, value: token.token)
264-
DataConnectLogger.debug("App Check token added.")
265-
} else {
266-
DataConnectLogger.debug("App Check token unavailable. Not adding App Check header.")
267-
}
268-
} catch {
269-
DataConnectLogger.debug(
270-
"Cannot get App Check token successfully due to: \(error). Not adding App Check header."
271-
)
262+
if let token = await appCheck?.getToken(forcingRefresh: false) {
263+
headers.add(name: RequestHeaders.appCheckHeader, value: token.token)
264+
DataConnectLogger.debug("App Check token added.")
265+
} else {
266+
DataConnectLogger.debug("App Check token unavailable. Not adding App Check header.")
272267
}
273268

274269
var options = CallOptions(customMetadata: headers)

0 commit comments

Comments
 (0)