Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable AppCheck Support #6

Merged
merged 1 commit into from
Sep 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
aashishpatil-g marked this conversation as resolved.
Show resolved Hide resolved
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
Loading