Skip to content

Commit

Permalink
Enable AppCheck
Browse files Browse the repository at this point in the history
  • Loading branch information
cherylEnkidu committed Sep 16, 2024
1 parent ce9fb34 commit 764f26d
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions FirebaseDataConnect/Sources/Internal/GrpcClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ actor GrpcClient: CustomStringConvertible {

private let auth: Auth

private let appCheckEnabled = false

private let appCheck: AppCheck?

private enum RequestHeaders {
Expand Down Expand Up @@ -196,22 +194,20 @@ actor GrpcClient: CustomStringConvertible {
}

// Add AppCheck token if available
if appCheckEnabled {
do {
if let token = try await appCheck?.token(forcingRefresh: false) {
headers.add(name: RequestHeaders.appCheckHeader, value: "\(token)")
FirebaseLogger.dataConnect
.debug("App Check token added: \(token)")
} else {
FirebaseLogger.dataConnect
.debug("App Check token unavailable. Not adding App Check header.")
}
} catch {
do {
if let token = try await appCheck?.token(forcingRefresh: false) {
headers.add(name: RequestHeaders.appCheckHeader, value: token.token)
FirebaseLogger.dataConnect
.debug("App Check token added: \(token.token)")
} else {
FirebaseLogger.dataConnect
.debug(
"Cannot get App Check token successfully due to: \(error). Not adding App Check header."
)
.debug("App Check token unavailable. Not adding App Check header.")
}
} catch {
FirebaseLogger.dataConnect
.debug(
"Cannot get App Check token successfully due to: \(error). Not adding App Check header."
)
}

let options = CallOptions(customMetadata: headers)
Expand Down

0 comments on commit 764f26d

Please sign in to comment.