Bigair
Bigair

Reputation: 1592

Firebase app distribution via Fastlane "the server responded with status 403"

I setup Firebase app distribution feature in Fastlane Fastfile to distribute beta version of my iOS app. It was working fine but It suddenly started showing errors.

This is how my lane looks like.

lane :distribute_beta do |options|
        
        sync_code_signing_adhoc()
        update_build_number_of_all_frameworks() 
        build_ios_app_adhoc()

        firebase_app_distribution(
            app: "<app ID here>",
            testers: "<tester emials here>",
            release_notes: options[:release_note],
            firebase_cli_path: "/usr/local/bin/firebase"
        )
end  

When I run this lane it shows error

the server responded with status 403

on Step: firebase_app_distribution

Log also says authentication to google succeeded.

 Authenticating with GOOGLE_APPLICATION_CREDENTIALS environment variable: /<path to cred>/<cred_file_name>.json
 🔐 Authenticated successfully.

Following is entire error around "Step: firebase_app_distribution "

[17:11:04]: ---------------------------------------
[17:11:04]: --- Step: firebase_app_distribution ---
[17:11:04]: ---------------------------------------
[17:11:04]: Authenticating with GOOGLE_APPLICATION_CREDENTIALS environment variable: /<path to cred>/<cred_file_name>.json
[17:11:04]: 🔐 Authenticated successfully.
+------------------------------------+---------------------------------------------+
|                                   Lane Context                                   |
+------------------------------------+---------------------------------------------+
| DEFAULT_PLATFORM                   | ios                                         |
| PLATFORM_NAME                      | ios                                         |
| LANE_NAME                          | ios distribute_beta                         |
| SIGH_PROFILE_TYPE                  | ad-hoc                                      |
| MATCH_PROVISIONING_PROFILE_MAPPING | {"<my bndle ID>"=>"match AdHoc              |
|                                    | <my bundle ID>"}                            |
| BUILD_NUMBER                       | 107                                         |
| IPA_OUTPUT_PATH                    | /Users/my_user_name/Repository/App/App|
|                                    | y/App.ipa                                   |
| XCODEBUILD_ARCHIVE                 | /Users/my_user_name/Library/Developer/Xcode/A|
|                                    | rchives/2021-01-08/App 2021-01-08           |
|                                    | 17.09.08.xcarchive                          |
| DSYM_OUTPUT_PATH                   | /Users/my_user_name/Repository/App/App           |
|                                    | y/App.app.dSYM.zip                          |
+------------------------------------+---------------------------------------------+
[17:11:06]: the server responded with status 403

+------+-----------------------------+-------------+
|                 fastlane summary                 |
+------+-----------------------------+-------------+
| Step | Action                      | Time (in s) |
+------+-----------------------------+-------------+
| 1    | default_platform            | 0           |
| 2    | Switch to ios               | 0           |
|      | sync_code_signing_adhoc     |             |
|      | lane                        |             |
| 3    | sync_code_signing           | 18          |
| 4    | Switch to ios               | 0           |
|      | update_build_number_of_all  |             |
|      | _frameworks lane            |             |
| 5    | increment_build_number      | 1           |
| 6    | commit_version_bump         | 0           |
| 7    | Switch to ios               | 0           |
|      | build_ios_app_adhoc lane    |             |
| 8    | build_ios_app               | 126         |
| 💥   | firebase_app_distribution   | 1           |
+------+-----------------------------+-------------+

[17:11:06]: fastlane finished with errors

How can I fix this?

Upvotes: 17

Views: 14514

Answers (8)

Adam Ri
Adam Ri

Reputation: 517

My experience with Firebase App Distribution and Fastlane was a bit different from what's outlined in the tutorial (https://developersancho.medium.com/ci-cd-firebase-app-distribution-with-fastlane-on-android-8ee419f770b7). In the tutorial, it recommends using a private JSON file for authentication, but I encountered some challenges with this approach. Here's what I did to resolve the issue:

Initially, I set up Firebase App Distribution in Fastlane with a private JSON file in my configuration like this:

firebase_app_distribution(
    app: ENV["FIREBASE_APP_ID"],
    apk_path: apk_path,
    release_notes: "#{release_note}",
    groups_file: "fastlane/groups.txt",
    service_credentials_file: ENV["FIREBASE_LOGIN_CREDENTIALS"]
)

However, I found that the private JSON file approach wasn't working for me. I attempted to authenticate using the Firebase CLI and used the token, as some other answers suggested (using firebase_cli_token), but unfortunately, this didn't resolve the issue either.

As a workaround, I decided to remove the usage of the private JSON file from my Fastlane setup, resulting in the following configuration:

firebase_app_distribution(
    app: ENV["FIREBASE_APP_ID"],
    apk_path: apk_path,
    release_notes: "#{release_note}",
    groups_file: "fastlane/groups.txt"
)

After making this change, I encountered an error message from Fastlane stating that it couldn't find any credentials. However, the interesting part is that it proceeded to use "cached Firebase CLI credentials" and miraculously, the distribution process worked.

Upvotes: 0

Nino van Hooff
Nino van Hooff

Reputation: 3893

Another thing to check is whether your App ID is set correctly. You can find it in the Firebase project settings.

You might hit this problem when you create a new app flavor (like dev vs. prod, acceptance etc) and you forget to update the app_id or serviceAccount file

Upvotes: 0

Genix
Genix

Reputation: 192

Also, make sure that you are logged in with an appropriate account (the reason for my error 😅).

Upvotes: 0

phnmnn
phnmnn

Reputation: 13250

Check that your firebase account have distribution permission for project. Project settings -> Users and permissions -> Member should be with "Editor" role

Upvotes: 0

RealityExpander
RealityExpander

Reputation: 334

For me, I had to add the particular account I was using for App Distribution login to the Project settings for my app.

enter image description here

Upvotes: 0

aprilmintacpineda
aprilmintacpineda

Reputation: 1274

As for me, it was because the service account that I am using does not have Firebase App Distribution Admin role. https://firebase.google.com/docs/app-distribution/authenticate-service-account?platform=ios

I simply had to edit my existing service, to do that, go to firebase console > project settings > Service accounts > then click on the service accounts as shown in the image below

enter image description here

It will take you to GCP IAM and Admin where you can find and edit the role of your service account.

Upvotes: 8

Bartłomiej Semańczyk
Bartłomiej Semańczyk

Reputation: 61814

  1. Simply run the following command on console:

    curl -sL https://firebase.tools | bash
    
  2. then, authenticate on the browser

  3. Then run

    firebase login:ci
    
  4. After success you will get printed your new cli token, like this:

Waiting for authentication...

✔  Success! Use this token to login on a CI server:

1//here_will_be_your_new_token

Example: firebase deploy --token "$FIREBASE_TOKEN"

Upvotes: 6

4gus71n
4gus71n

Reputation: 4093

Usually, when you get that specific message it means that the Firebase Refresh Token is no longer valid.

So, when you submit the app, at some point, you have to specify the Firebase Refresh Token:

...
firebase_app_distrubution(
  ...
  firebase_cli_token: "<YourFirebaseRefreshToken>"
)
...

You can get this token from here. If your script started to fail out of nowhere, that probably means that whoever generated this (or any other authentication token) got removed from the Firebase project.

If you're getting a 403 that definitely means that either someone got removed from your Firebase project or that someone removed/regenerated a token on the Firebase console.

Upvotes: 16

Related Questions