Skip to content

Commit

Permalink
Enable AppCheck Support (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
cherylEnkidu authored Sep 18, 2024
1 parent 9a151ed commit 52e39a8
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions Sources/Internal/GrpcClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ actor GrpcClient: CustomStringConvertible {

private let auth: Auth

private let appCheckEnabled = false

private let appCheck: AppCheck?

private enum RequestHeaders {
Expand Down Expand Up @@ -195,22 +193,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 52e39a8

Please sign in to comment.