Created
March 21, 2025 06:34
-
-
Save ferbass/cf2b0452c82543030c7f834c1faca5e9 to your computer and use it in GitHub Desktop.
Generate and Test AppStoreConnect API Key
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'jwt' | |
require 'net/http' | |
require 'uri' | |
require 'json' | |
KEY_ID = "" | |
PRIVATE_KEY_PATH = ".p8" | |
API_URL = "https://api.appstoreconnect.apple.com/v1/apps" | |
private_key = OpenSSL::PKey::EC.new(File.read(PRIVATE_KEY_PATH)) | |
token = JWT.encode( | |
{ | |
sub: 'user, | |
exp: Time.now.to_i + 600, | |
aud: "appstoreconnect-v1" | |
}, | |
private_key, | |
'ES256', | |
kid: KEY_ID | |
) | |
puts "Generated Token: #{token}" | |
uri = URI.parse(API_URL) | |
request = Net::HTTP::Get.new(uri) | |
request["Authorization"] = "Bearer #{token}" | |
request["Content-Type"] = "application/json" | |
response = Net::HTTP.start(uri.host, uri.port, use_ssl: true) do |http| | |
http.request(request) | |
end | |
puts "Response Code: #{response.code}" | |
puts "Response Body: #{response.body}" | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'jwt' | |
require 'net/http' | |
require 'uri' | |
require 'json' | |
KEY_ID = "" | |
ISSUER_ID = "" | |
PRIVATE_KEY_PATH = ".p8" | |
API_URL = "https://api.appstoreconnect.apple.com/v1/apps" | |
private_key = OpenSSL::PKey::EC.new(File.read(PRIVATE_KEY_PATH)) | |
token = JWT.encode( | |
{ | |
iss: ISSUER_ID, | |
exp: Time.now.to_i + 600, | |
aud: "appstoreconnect-v1" | |
}, | |
private_key, | |
'ES256', | |
kid: KEY_ID | |
) | |
puts "Generated Token: #{token}" | |
uri = URI.parse(API_URL) | |
request = Net::HTTP::Get.new(uri) | |
request["Authorization"] = "Bearer #{token}" | |
request["Content-Type"] = "application/json" | |
response = Net::HTTP.start(uri.host, uri.port, use_ssl: true) do |http| | |
http.request(request) | |
end | |
puts "Response Code: #{response.code}" | |
puts "Response Body: #{response.body}" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment