エラー内容
Fastlaneでipaをストアへアップロードする際、2ファクタ認証しているアカウントの場合は以下のようなエラーが表示されます。
Uploading binary to App Store Connect
Going to upload updated app to App Store Connect
This might take a few minutes. Please don't interrupt the script.
[Transporter Error Output]: Sign in with the app-specific password you generated. If you forgot the app-specific password or need to create a new one, go to appleid.apple.com (-22938)
Transporter transfer failed.
Sign in with the app-specific password you generated. If you forgot the app-specific password or need to create a new one, go to appleid.apple.com (-22938)
Your account has 2 step verification enabled
Please go to https://appleid.apple.com/account/manage
and generate an application specific password for
the iTunes Transporter, which is used to upload builds
To set the application specific password on a CI machine using
an environment variable, you can set the FASTLANE_APPLE_APPLICATION_SPECIFIC_PASSWORD variable
-------------------------------------------------------------------------------------
Please provide your Apple Developer Program account credentials[0m
The login information you enter will be stored in your macOS Keychain[0m
-------------------------------------------------------------------------------------
この場合の対応方法を記載しておきます。
概要
- ApplicationSpecificPasswordの作成
- fastlaneの
FASTLANE_APPLE_APPLICATION_SPECIFIC_PASSWORD
を設定する -
FASTLANE_SESSION
の生成 -
FASTLANE_SESSION
を環境変数に設定
詳細手順
(1)ApplicationSpecificPasswordの作成
Appleアカウントの管理ページにログインする
この時点で2ファクタ認証が必要です。
ログインしたら下記のApp用パスワードから「パスワードを生成」リンクを押します。
「パスワードを生成」を押すとラベルの入力を求められます。自分が分かる任意の名前で問題ないので、「XXアプリfastlane用」などと付けておきます。

生成されたパスワードは一度しか表示されないので、必ずコピーしておいてください。
万が一、コピーできなかった場合などはもう一度作り直し、パスワードが分からなくなったものは削除しておきましょう。
(2)fastlaneのFASTLANE_APPLE_APPLICATION_SPECIFIC_PASSWORD
を設定する
fastlaneの環境変数にFASTLANE_APPLE_APPLICATION_SPECIFIC_PASSWORD
というものがあるので、そこに(1)で作成したパスワードを設定します。
ENV["FASTLANE_APPLE_APPLICATION_SPECIFIC_PASSWORD"] = "(1)で生成したパスワード"
(3)FASTLANE_SESSION
の生成
以下のspaceauth
コマンドで生成することができます。メールアドレスは2ファクタ認証のかかったAppleIDを使います。
$ fastlane spaceauth -u AppleIDのメールアドレス@email.com
実行するとAppleIDのパスワードと、2ファクタ認証の6桁の数字を聞かれますので、適宜入力してください。
その後、以下のログが出力されます。
❯ fastlane spaceauth -u AppleIDのメールアドレス@email.com
[✔] 🚀
Logging into to App Store Connect (AppleIDのメールアドレス@email.com)...
Successfully logged in to App Store Connect
---
Pass the following via the FASTLANE_SESSION environment variable:
---\n- !ruby/object:HTTP::Cookie\n name: xxxxxxxxxxxx\n value: (長い文字列)\n domain: idmsa.apple.com\n for_domain: true\n path: "/"\n secure: true\n httponly: true\n expires: \n max_age: 2592000\n created_at: 2020-08-21 12:54:46.0000000000 +09:00\n accessed_at: 2020-08-24 20:16:49.000000000 +09:00\n- !ruby/object:HTTP::Cookie\n name: myacinfo\n value: (長い文字列)\n domain: apple.com\n for_domain: true\n path: "/"\n secure: true\n httponly: true\n expires: \n max_age: \n created_at: 2020-08-24 20:16:50.000000000 +09:00\n accessed_at: 2020-08-24 20:16:50.000000000 +09:00\n- !ruby/object:HTTP::Cookie\n name: dqsid\n value: (長い文字列)\n domain: appstoreconnect.apple.com\n for_domain: false\n path: "/"\n secure: true\n httponly: true\n expires: \n max_age: 1800\n created_at: &1 2020-08-24 20:16:50.000000000 +09:00\n accessed_at: *1\n
Example:
export FASTLANE_SESSION=(上と同じ長い文字列郡)
なお、有効期限は1ヶ月で、コマンドを打つ度にこのセッションは更新されます。
(4)FASTLANE_SESSION
を環境変数に設定
(3)のログにもあったように、以下のコマンドなどでFASTLANE_SESSION
環境変数にセッションの値を設定します。
export FASTLANE_SESSION=(上で取得できた長い文字列郡)
echoで出力するとこのようになっています。
$ echo $FASTLANE_SESSION
---
- !ruby/object:HTTP::Cookie
name: xxxxxxxxxxxx
value: (長い文字列)
domain: idmsa.apple.com
for_domain: true
path: "/"
secure: true
httponly: true
expires:
max_age: 2592000
created_at: 2020-08-21 12:54:46.0000000000 +09:00
accessed_at: 2020-08-24 20:16:49.000000000 +09:00
- !ruby/object:HTTP::Cookie
name: myacinfo
value: (長い文字列)
domain: apple.com
for_domain: true
path: "/"
secure: true
httponly: true
expires:
max_age:
created_at: 2020-08-24 20:16:50.000000000 +09:00
accessed_at: 2020-08-24 20:16:50.000000000 +09:00
- !ruby/object:HTTP::Cookie
name: dqsid
value: (長い文字列)
domain: appstoreconnect.apple.com
for_domain: false
path: "/"
secure: true
httponly: true
expires:
max_age: 1800
created_at: &1 2020-08-24 20:16:50.000000000 +09:00
accessed_at: *1
以上で設定は完了です。