Skip to content

Callable Function fails with 'UNAUTHENTICATED' (Code 16) despite correct configuration and authenticated client #15054

Open
@Haniubub

Description

@Haniubub

Description

Expected Behavior:
When a successfully authenticated iOS user calls an https.onCall Cloud Function, the backend function's context.auth object should be populated with the user's authentication data (UID, token, etc.). The function should then execute its logic and return a successful response to the client.

Actual Behavior:
The Cloud Function call from the iOS app consistently fails. The client-side SDK receives an UNAUTHENTICATED (Code 16) error from the com.firebase.functions domain.

Backend logs have previously confirmed that the context.auth object is undefined when the function is invoked. This causes the function's own auth check (if (!context.auth)) to fail and correctly throw the unauthenticated error back to the client.

The core issue appears to be that the Google Cloud/Firebase infrastructure is not correctly passing the validated authentication context to the Cloud Function's runtime environment for this specific project, even though the client is verifiably authenticated before making the call.

Reproducing the issue

Steps to Reproduce:

Set up the provided iOS project with the correct GoogleService-Info.plist for the project.

Deploy the provided Node.js Cloud Function code (generateRecipe) to the same project.

Launch the iOS app on a clean simulator. The app will successfully sign in anonymously.

Call the generateRecipe Cloud Function from the app.

Observe the logs in the Xcode console, which will show the UNAUTHENTICATED error.

Exhaustive Troubleshooting Already Performed:
This issue persists despite verifying that every user-configurable aspect is correct:

Client SDK: Using current version 10.25.0 of firebase-ios-sdk. The function call is correctly made via https.Callable.

Project Setup: The project is new, and Firestore is confirmed to be in Native Mode.

Configuration: The correct GoogleService-Info.plist is embedded in the Xcode app target.

Backend Deployment: The function has been successfully deployed multiple times (Successful update operation).

Backend Code: The index.js code correctly checks for context.auth and is logically sound.

APIs & Permissions: All required APIs (Identity Toolkit, Cloud Run, etc.) are enabled. The function's service account has been granted both Editor and Cloud Run Admin IAM roles.

Local Environment: The entire local environment (Xcode caches, DerivedData, the iOS Simulator, and the Mac itself) has been completely reset multiple times.

Region Check: No region mismatch exists between the function (us-central1) and Firestore (nam5).

Firebase SDK Version

11.15.0

Xcode Version

16.2

Installation Method

Swift Package Manager

Firebase Product(s)

Authentication, Functions, Firestore

Targeted Platforms

iOS

Relevant Log Output

Detailed Error from Cloud Function:
   -> Code: unauthenticated (16)
   -> Domain: com.firebase.functions
   -> Message: This operation requires authentication.
   -> Details: no details

If using Swift Package Manager, the project's Package.resolved

{
"originHash" : "c63c63846d9c539229e96de38d6af51417e28c0ee9a0bc48bd0f0f19d923c329",
"pins" : [
{
"identity" : "abseil-cpp-binary",
"kind" : "remoteSourceControl",
"location" : "https://github.com/google/abseil-cpp-binary.git",
"state" : {
"revision" : "bbe8b69694d7873315fd3a4ad41efe043e1c07c5",
"version" : "1.2024072200.0"
}
},
{
"identity" : "app-check",
"kind" : "remoteSourceControl",
"location" : "https://github.com/google/app-check.git",
"state" : {
"revision" : "61b85103a1aeed8218f17c794687781505fbbef5",
"version" : "11.2.0"
}
},
{
"identity" : "firebase-ios-sdk",
"kind" : "remoteSourceControl",
"location" : "https://github.com/firebase/firebase-ios-sdk",
"state" : {
"revision" : "fdc352fabaf5916e7faa1f96ad02b1957e93e5a5",
"version" : "11.15.0"
}
},
{
"identity" : "google-ads-on-device-conversion-ios-sdk",
"kind" : "remoteSourceControl",
"location" : "https://github.com/googleads/google-ads-on-device-conversion-ios-sdk",
"state" : {
"revision" : "428d8bb138e00f9a3f4f61cc6cd8863607524f65",
"version" : "2.1.0"
}
},
{
"identity" : "googleappmeasurement",
"kind" : "remoteSourceControl",
"location" : "https://github.com/google/GoogleAppMeasurement.git",
"state" : {
"revision" : "45ce435e9406d3c674dd249a042b932bee006f60",
"version" : "11.15.0"
}
},
{
"identity" : "googledatatransport",
"kind" : "remoteSourceControl",
"location" : "https://github.com/google/GoogleDataTransport.git",
"state" : {
"revision" : "617af071af9aa1d6a091d59a202910ac482128f9",
"version" : "10.1.0"
}
},
{
"identity" : "googleutilities",
"kind" : "remoteSourceControl",
"location" : "https://github.com/google/GoogleUtilities.git",
"state" : {
"revision" : "60da361632d0de02786f709bdc0c4df340f7613e",
"version" : "8.1.0"
}
},
{
"identity" : "grpc-binary",
"kind" : "remoteSourceControl",
"location" : "https://github.com/google/grpc-binary.git",
"state" : {
"revision" : "cc0001a0cf963aa40501d9c2b181e7fc9fd8ec71",
"version" : "1.69.0"
}
},
{
"identity" : "gtm-session-fetcher",
"kind" : "remoteSourceControl",
"location" : "https://github.com/google/gtm-session-fetcher.git",
"state" : {
"revision" : "c756a29784521063b6a1202907e2cc47f41b667c",
"version" : "4.5.0"
}
},
{
"identity" : "interop-ios-for-google-sdks",
"kind" : "remoteSourceControl",
"location" : "https://github.com/google/interop-ios-for-google-sdks.git",
"state" : {
"revision" : "040d087ac2267d2ddd4cca36c757d1c6a05fdbfe",
"version" : "101.0.0"
}
},
{
"identity" : "leveldb",
"kind" : "remoteSourceControl",
"location" : "https://github.com/firebase/leveldb.git",
"state" : {
"revision" : "a0bc79961d7be727d258d33d5a6b2f1023270ba1",
"version" : "1.22.5"
}
},
{
"identity" : "nanopb",
"kind" : "remoteSourceControl",
"location" : "https://github.com/firebase/nanopb.git",
"state" : {
"revision" : "b7e1104502eca3a213b46303391ca4d3bc8ddec1",
"version" : "2.30910.0"
}
},
{
"identity" : "promises",
"kind" : "remoteSourceControl",
"location" : "https://github.com/google/promises.git",
"state" : {
"revision" : "540318ecedd63d883069ae7f1ed811a2df00b6ac",
"version" : "2.4.0"
}
},
{
"identity" : "swift-protobuf",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-protobuf.git",
"state" : {
"revision" : "102a647b573f60f73afdce5613a51d71349fe507",
"version" : "1.30.0"
}
}
],
"version" : 3
}

If using CocoaPods, the project's Podfile.lock

Not applicable (using Swift Package Manager).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions