fastlane / fastlane

🚀 The easiest way to automate building and releasing your iOS and Android apps
https://fastlane.tools
MIT License
39.3k stars 5.67k forks source link

build failed with msg: Authentication credentials are missing or invalid. #21160

Closed iTofu closed 11 months ago

iTofu commented 1 year ago

New Issue Checklist

Issue Description

(Note: ASC = App Store Connect)

I created a new project, and then tried to build it with fastlane and upload it to TestFlight, but there is an error occur on upload:

[16:58:08]: Authentication credentials are missing or invalid. - Provide a properly configured and signed bearer token, and make sure that it has not expired. Learn more about Generating Tokens for API Requests https://developer.apple.com/go/?id=api-generating-tokens

I checked the issues related to this error and it didn't seem to help my case (I made sure the ASC API Keys was correct), so I created this issue.

And, I have another app, which is also under this asc team, and it builds and uploads normally. I have tried to use the same ASC api key in the new project, or to create a new api key in ASC, both of these errors occurred

[16:58:01]: Cruising back to lane 'ios tf' 🚘
[16:58:01]: --------------------------------------------
[16:58:01]: --- Step: Switch to ios asc_api_key lane ---
[16:58:01]: --------------------------------------------
[16:58:01]: Cruising over to lane 'ios asc_api_key' 🚖
[16:58:01]: ---------------------------------------
[16:58:01]: --- Step: app_store_connect_api_key ---
[16:58:01]: ---------------------------------------
[16:58:01]: Cruising back to lane 'ios tf' 🚘
[16:58:01]: ----------------------------------
[16:58:01]: --- Step: upload_to_testflight ---
[16:58:01]: ----------------------------------
[16:58:01]: Creating authorization token for App Store Connect API
+---------------------------------+---------------------------------+
|                           Lane Context                            |
+---------------------------------+---------------------------------+
| DEFAULT_PLATFORM                | ios                             |
| PLATFORM_NAME                   | ios                             |
| LANE_NAME                       | ios tf                          |
| VERSION_NUMBER                  | 1.00.01                         |
| SIGH_PROFILE_TYPE               | app-store                       |
| MATCH_PROVISIONING_PROFILE_MAP  | {"xx.yy.zz"=>"match   |
| PING                            | AppStore xx.yy.zz",   |
|                                 | "xx.yy.zz.PushServic  |
|                                 | e"=>"match AppStore             |
|                                 | xx.yy.zz.PushService  |
|                                 | ",                              |
|                                 | "xx.yy.zz.PushConten  |
|                                 | t"=>"match AppStore             |
|                                 | xx.yy.zz.PushContent  |
|                                 | "}                              |
| GIT_REPO_WAS_CLEAN_ON_START     | true                            |
| BUILD_NUMBER                    | 5                               |
| IPA_OUTPUT_PATH                 | /xx/yy.ipa  |
| XCODEBUILD_ARCHIVE              | /Users/zz/Library/Developer/X  |
|                                 | code/Archives/2023-03-24/yy  |
|                                 | 2023-03-24 16.54.52.xcarchive   |
| DSYM_OUTPUT_PATH                | /xx/yy.app.dSYM.zip  |
+---------------------------------+---------------------------------+
[16:58:08]: Authentication credentials are missing or invalid. - Provide a properly configured and signed bearer token, and make sure that it has not expired. Learn more about Generating Tokens for API Requests https://developer.apple.com/go/?id=api-generating-tokens

+------+---------------------+-------------+
|             fastlane summary             |
+------+---------------------+-------------+
| Step | Action              | Time (in s) |
+------+---------------------+-------------+
| 1    | default_platform    | 0           |
| 2    | get_version_number  | 0           |
| 3    | Switch to ios       | 0           |
|      | c_build_app lane    |             |
| 4    | Switch to ios       | 0           |
|      | match_cer lane      |             |
| 5    | match               | 1           |
| 6    | ensure_git_status_  | 0           |
|      | clean               |             |
| 14   | cocoapods           | 3           |
| 15   | build_app           | 227         |
| 16   | Switch to ios       | 0           |
|      | asc_api_key lane    |             |
| 17   | app_store_connect_  | 0           |
|      | api_key             |             |
| 💥   | upload_to_testflig  | 6           |
|      | ht                  |             |
+------+---------------------+-------------+

[16:58:08]: fastlane finished with errors

Looking for related GitHub issues on fastlane/fastlane...

[!] The request could not be completed because:
    Authentication credentials are missing or invalid. - Provide a properly configured and signed bearer token, and make sure that it has not expired. Learn more about Generating Tokens for API Requests https://developer.apple.com/go/?id=api-generating-tokens
Command executed
# tf is a custom lane, check the key code below
bundle exec fastlane tf 
Complete output when running fastlane, including the stack trace and command used
There is the key code in running fastlane file:

```
# asc api key
@key_id = ENV['ASC_KEY_ID']
@issuer_id = ENV['ASC_ISSUER_ID']
@key_filepath = ENV['ASC_KEY_FILEPATH']

app_store_connect_api_key(
    key_id: @key_id,
    issuer_id: @issuer_id,
    key_filepath: @key_filepath,
    duration: 1200, # optional (maximum 1200)
    in_house: true # optional but may be required if using match/sigh
)

# upload to tf
upload_to_testflight(
    skip_waiting_for_build_processing: true
)
```

Environment

 
✅ fastlane environment ✅ ### Stack | Key | Value | | --------------------------- | ------------------------------------------- | | OS | 13.2 | | Ruby | 3.0.0 | | Bundler? | true | | Git | git version 2.37.1 (Apple Git-137.1) | | Installation Source | ~/.rvm/gems/ruby-3.0.0/bin/fastlane | | Host | macOS 13.2 (22D49) | | Ruby Lib Dir | ~/.rvm/rubies/ruby-3.0.0/lib | | OpenSSL Version | OpenSSL 1.1.1m 14 Dec 2021 | | Is contained | false | | Is homebrew | false | | Is installed via Fabric.app | false | | Xcode Path | /Applications/Xcode.app/Contents/Developer/ | | Xcode Version | 14.2 | | Swift Version | 5.7.2 | ### System Locale | Variable | Value | | | -------- | ----------- | - | | LANG | en_US.UTF-8 | ✅ | | LC_ALL | en_US.UTF-8 | ✅ | | LANGUAGE | | | ### fastlane files: (Unable to provide) There is the key code in running fastlane file: ``` # asc api key @key_id = ENV['ASC_KEY_ID'] @issuer_id = ENV['ASC_ISSUER_ID'] @key_filepath = ENV['ASC_KEY_FILEPATH'] app_store_connect_api_key( key_id: @key_id, issuer_id: @issuer_id, key_filepath: @key_filepath, duration: 1200, # optional (maximum 1200) in_house: true # optional but may be required if using match/sigh ) # upload to tf upload_to_testflight( skip_waiting_for_build_processing: true ) ``` ### fastlane gems | Gem | Version | Update-Status | | -------- | ------- | ------------- | | fastlane | 2.212.1 | ✅ Up-To-Date | ### Loaded fastlane plugins: | Plugin | Version | Update-Status | | ------------------------- | ------- | ------------- | | fastlane-plugin-appcenter | 2.0.0 | ✅ Up-To-Date | | fastlane-plugin-firim | 0.2.2 | ✅ Up-To-Date | | fastlane-plugin-pgyer | 0.2.4 | ✅ Up-To-Date |
Loaded gems | Gem | Version | | ------------------------------- | ------------ | | did_you_mean | 1.6.3 | | bundler | 2.4.7 | | pathname | 0.2.1 | | rake | 13.0.6 | | rexml | 3.2.5 | | CFPropertyList | 3.0.6 | | concurrent-ruby | 1.2.2 | | i18n | 1.12.0 | | minitest | 5.18.0 | | tzinfo | 2.0.6 | | zeitwerk | 2.6.7 | | activesupport | 6.1.7.3 | | public_suffix | 4.0.7 | | addressable | 2.8.1 | | httpclient | 2.8.3 | | json | 2.6.3 | | algoliasearch | 1.27.5 | | artifactory | 3.0.15 | | atomos | 0.1.3 | | aws-eventstream | 1.2.0 | | aws-partitions | 1.733.0 | | aws-sigv4 | 1.5.2 | | jmespath | 1.6.2 | | aws-sdk-core | 3.171.0 | | aws-sdk-kms | 1.63.0 | | aws-sdk-s3 | 1.119.2 | | babosa | 1.0.4 | | claide | 1.1.0 | | fuzzy_match | 2.0.4 | | nap | 1.1.0 | | netrc | 0.11.0 | | ffi | 1.15.5 | | ethon | 0.16.0 | | typhoeus | 1.4.0 | | cocoapods-core | 1.11.3 | | cocoapods-deintegrate | 1.0.5 | | cocoapods-downloader | 1.6.3 | | cocoapods-plugins | 1.0.0 | | cocoapods-search | 1.0.1 | | cocoapods-trunk | 1.6.0 | | cocoapods-try | 1.2.0 | | colored2 | 3.1.2 | | escape | 0.0.4 | | fourflusher | 2.3.1 | | gh_inspector | 1.1.3 | | molinillo | 0.8.0 | | ruby-macho | 2.5.1 | | nanaimo | 0.3.0 | | xcodeproj | 1.22.0 | | cocoapods | 1.11.3 | | cocoapods-pod-linkage | 0.0.1 | | colored | 1.2 | | highline | 2.0.3 | | commander | 4.6.0 | | declarative | 0.0.20 | | digest-crc | 0.6.4 | | unf_ext | 0.0.8.2 | | unf | 0.1.4 | | domain_name | 0.5.20190701 | | dotenv | 2.8.1 | | emoji_regex | 3.2.3 | | excon | 0.99.0 | | faraday-em_http | 1.0.0 | | faraday-em_synchrony | 1.0.0 | | faraday-excon | 1.1.0 | | faraday-httpclient | 1.0.1 | | multipart-post | 2.0.0 | | faraday-multipart | 1.0.4 | | faraday-net_http | 1.0.1 | | faraday-net_http_persistent | 1.2.0 | | faraday-patron | 1.0.0 | | faraday-rack | 1.0.0 | | faraday-retry | 1.0.3 | | ruby2_keywords | 0.0.5 | | faraday | 1.10.3 | | http-cookie | 1.0.5 | | faraday-cookie_jar | 0.0.7 | | faraday_middleware | 1.2.0 | | fastimage | 2.2.6 | | jwt | 2.7.0 | | memoist | 0.16.2 | | multi_json | 1.15.0 | | os | 1.1.4 | | signet | 0.17.0 | | googleauth | 1.5.0 | | mini_mime | 1.1.2 | | trailblazer-option | 0.1.2 | | uber | 0.1.0 | | representable | 3.2.0 | | retriable | 3.1.2 | | webrick | 1.8.1 | | google-apis-core | 0.11.0 | | google-apis-androidpublisher_v3 | 0.37.0 | | google-apis-playcustomapp_v1 | 0.13.0 | | google-apis-iamcredentials_v1 | 0.17.0 | | google-apis-storage_v1 | 0.19.0 | | google-cloud-env | 1.6.0 | | google-cloud-errors | 1.3.1 | | google-cloud-core | 1.6.0 | | google-cloud-storage | 1.44.0 | | mini_magick | 4.12.0 | | naturally | 2.2.1 | | optparse | 0.1.1 | | plist | 3.7.0 | | rubyzip | 2.3.2 | | security | 0.1.3 | | simctl | 1.6.10 | | terminal-notifier | 2.0.0 | | unicode-display_width | 1.8.0 | | terminal-table | 1.8.0 | | tty-screen | 0.8.1 | | tty-cursor | 0.7.1 | | tty-spinner | 0.9.3 | | word_wrap | 1.0.0 | | rouge | 2.0.7 | | xcpretty | 0.3.0 | | xcpretty-travis-formatter | 1.0.1 | | fastlane-plugin-appcenter | 2.0.0 | | firim | 0.2.9 | | fastlane-plugin-firim | 0.2.2 | | fastlane-plugin-pgyer | 0.2.4 | | stringio | 3.0.5 | | psych | 5.1.0 | | xcode-install | 2.8.1 |
*generated on:* **2023-03-24**
guy-shahine commented 1 year ago

We were able to work around the issue by removing duration: 1200 as a parameter to app_store_connect_api_key

iTofu commented 1 year ago

We were able to work around the issue by removing duration: 1200 as a parameter to app_store_connect_api_key

Thanks for your reply. I tried it and removed the duration parameter, but the same problem still exists. In addition, errors occurred in upload_to_testflight (upload to tf), not app_store_connect_api_key (request asc api key)

starfall-9000 commented 1 year ago

@iTofu have you set params apple_id as pilot parameters. Reference from pilot fastlane documents

pilot/upload_to_testflight can use an [Application Specific Password via the FASTLANE_APPLE_APPLICATION_SPECIFIC_PASSWORD environment variable](https://docs.fastlane.tools/best-practices/continuous-integration/#application-specific-passwords) to upload a binary if both the skip_waiting_for_build_processing and apple_id options are set. (If any of those are not set, it will use the normal Apple login process that might require 2FA authentication.)

notice that apple_id is the Apple ID property in the App Information section in App Store Connect, it is not same as your apple_id in AppFile config.

I'm not sure how it affected, but it works for me.

you can reach more here https://docs.fastlane.tools/actions/pilot/

iTofu commented 1 year ago

@iTofu have you set params apple_id as pilot parameters. Reference from pilot fastlane documents

pilot/upload_to_testflight can use an [Application Specific Password via the FASTLANE_APPLE_APPLICATION_SPECIFIC_PASSWORD environment variable](https://docs.fastlane.tools/best-practices/continuous-integration/#application-specific-passwords) to upload a binary if both the skip_waiting_for_build_processing and apple_id options are set. (If any of those are not set, it will use the normal Apple login process that might require 2FA authentication.)

notice that apple_id is the Apple ID property in the App Information section in App Store Connect, it is not same as your apple_id in AppFile config.

I'm not sure how it affected, but it works for me.

you can reach more here https://docs.fastlane.tools/actions/pilot/

Thanks for your reply.

I tried adding apple_id manually, but it still didn't work. In addition, I communicate with ASC through App Store Connect API Key, so there is no need for apple_id

MagFer commented 1 year ago

I've just seen the same error while I was renewing the certificates. In my case, the error message was not related to the fundamental issue.

If you've updated AppStore Connect API key, verify the Issuer ID, the Key ID, and the key file path in your local machine match with the Fastfile code.

AppStore Connect -> Users & Access -> Keys

image

Fastfile

image

iTofu commented 1 year ago

I've just seen the same error while I was renewing the certificates. In my case, the error message was not related to the fundamental issue.

If you've updated AppStore Connect API key, verify the Issuer ID, the Key ID, and the key file path in your local machine match with the Fastfile code.

AppStore Connect -> Users & Access -> Keys

image

Fastfile

image

Thank you for your reply.

I have reconfirmed that the relevant parameters are correct. And puts the result of app_store_connect_api_key(), which outputs an obviously valid string, like this:

[15:15:45]: app_store_connect_api_key: {:key_id=>"XXX", :issuer_id=>"\"XX-XX-XX", :key=>"-----BEGIN PRIVATE KEY-----\nXXX\n-----END PRIVATE KEY-----", :is_key_content_base64=>false, :duration=>500, :in_house=>true}
xinsight commented 11 months ago

I'm running into this issue currently. It happened before but "fixed itself" so it does seem to be sporatic and related to app store connect (and not with the actual tokens).

To get more info:

Run fastlane with --verbose. Also, look in /tmp/spaceship* for logs that show the responses from app store connect. You'll probably see something like:

GET apps: 401 {"errors"=>[{"status"=>"401", "code"=>"NOT_AUTHORIZED", "title"=>"Authentication credentials are missing or invalid.", "detail"=>"Provide a properly configured and signed bearer token, and make sure that it has not expired. Learn more about Generating Tokens for API Requests https://developer.apple.com/go/?id=api-generating-tokens"}]}

Unfortunately the actual requests are not logged, and to do that you need to set SPACESHIP_DEBUG=1 and then use the charles web proxy to see the requests. All this to determine that app store connect sometimes craps out.

iTofu commented 11 months ago

Sorry, I finally confirmed my problem because I entered an extra " for a certain value, which is a typo. Like this:

# …
key = "value""
# …
airmikec commented 4 months ago

_### Azure DevOps API Key Issues for deploying to Apple_ To get this to successfully work on Azure DevOps Pipeline with an API Key. I ran into so many problems and tried everything I could find and this finally worked. Azure DevOps says you need use the base64 key. Well if you open up the .p8 and copy the base64 encoded string in there, that isn't what they want. They literally want you to copy all of the contenxt in the .p8 file to a base64 string. Don't modify the .p8 file. I found the solution at the follow source, and once you get the data.b64 file open it and copy the base64 string in that file. In the following article is discusses how to do this for Windows, Mac, and Ubuntu.

https://github.com/fastlane/fastlane/issues/21531#issuecomment-1873633417