App Store Connect API (.p8)
Legacy Apple authentication using email and passwords with 2FA requires storing session cookies (FASTLANE_SESSION) that expire every 30 days.
The official, non-expiring standard for CI/CD automation is the App Store Connect API Key (.p8).
1. Generating the Key in App Store Connect
- Navigate to App Store Connect → Users and Access → Integrations → App Store Connect API.
- Click Generate API Key.
- Name:
Fastlane CI. Access:Admin(orApp Manager). - Note three pieces of data:
- Key ID: 10-character string (e.g.,
D383X7YKP4). - Issuer ID: UUID string (e.g.,
69a6de70-xxxx-xxxx-xxxx-xxxxxxxxxxxx). - Private Key (
.p8): Download the key file (can only be downloaded once).
- Key ID: 10-character string (e.g.,
2. Using app_store_connect_api_key in Fastlane
Fastlane has a dedicated action app_store_connect_api_key that generates an in-memory JWT token valid for 20 minutes, automatically refreshed as needed.
lane :beta do # 1. Initialize API Key api_key = app_store_connect_api_key( key_id: ENV["APP_STORE_CONNECT_API_KEY_KEY_ID"], issuer_id: ENV["APP_STORE_CONNECT_API_KEY_ISSUER_ID"], key_content: ENV["APP_STORE_CONNECT_API_KEY_KEY"], # Raw base64 or plaintext .p8 content is_key_content_base64: true, in_house: false # true only for Enterprise Apple Developer programs )
# 2. Build iOS Archive build_app(scheme: "Production")
# 3. Upload to TestFlight using the API Key upload_to_testflight( api_key: api_key, skip_waiting_for_build_processing: true )endPassing API Key via Environment Variables:
If you define the following standard environment variables, actions like match, deliver, pilot, and cert detect them automatically without explicitly passing api_key:
APP_STORE_CONNECT_API_KEY_KEY_IDAPP_STORE_CONNECT_API_KEY_ISSUER_IDAPP_STORE_CONNECT_API_KEY_KEY_CONTENT
3. Programmatic Usage with Spaceship
The same App Store Connect API Key can be initialized directly inside Ruby code to manage capabilities, devices, and TestFlight groups programmatically:
Spaceship::ConnectAPI.token = Spaceship::ConnectAPI::Token.create( key_id: ENV["APP_STORE_CONNECT_API_KEY_KEY_ID"], issuer_id: ENV["APP_STORE_CONNECT_API_KEY_ISSUER_ID"], filepath: File.expand_path("AuthKey.p8", __dir__))For full implementations, see: