Skip to content

Instantly share code, notes, and snippets.

@enomoto
Last active November 13, 2023 05:29
Show Gist options
  • Save enomoto/28db90c7ca6b47c3c1e5bd8e58162224 to your computer and use it in GitHub Desktop.
Save enomoto/28db90c7ca6b47c3c1e5bd8e58162224 to your computer and use it in GitHub Desktop.
Generate JWT for App Store Connect API
require 'jwt'
require 'openssl'
# App Store Connect APIキー (.p8ファイル) の内容を読み込む
ecdsa_key = OpenSSL::PKey::EC.new(File.read("/path/to/your.p8"))
# Issuer ID (App Store Connectから取得)
# https://appstoreconnect.apple.com/access/api
issuer_id = "your_issuer_id"
# Key ID (App Store Connectから取得)
# https://appstoreconnect.apple.com/access/api
key_id = "your_key_id"
# 現在時刻
time_now = Time.now.to_i
# ヘッダーとペイロードの設定
headers = {
'kid' => key_id
}
payload = {
'iss' => issuer_id,
'exp' => time_now + 1200, # トークンの有効期限は発行から20分
'aud' => "appstoreconnect-v1"
}
# トークンの生成
token = JWT.encode payload, ecdsa_key, 'ES256', headers
puts "Generated JWT: #{token}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment