Hi there! Please could you publish some of the specifics for authentication for the new WeatherKit REST API? I am attempting to use something cobbled together from MapKit, and unfortunately WeatherKit returns a 500 error in response.
Broken code sample below. If you find a working solution or can identify an error, please comment with the solution. Thank you!
require 'http'
require 'jwt'
require 'openssl'
require 'logger'
p8 = OpenSSL::PKey::EC.new(File.read("/PATH/TO/DOWNLOADED/P8/FILE"))
token = JWT.encode({
iss: 'KEY_NAME_FROM_CIP',
iat: Time.now.to_i,
exp: Time.now.to_i + 3600,
aud: 'weatherkit',
}, p8, 'ES256', {
kid: 'KEY_ID_FROM_CIP',
typ: 'JWT'
})
res = HTTP.use(logging: {
logger: Logger.new(STDOUT)
}).headers(
"Authorization" => "Bearer #{token}"
).get "https://weatherkit.apple.com/api/v1/weather/en/LONG/LAT?dataSets=currentWeather&timezone=Europe/London"
puts "code: #{res.code}"
puts res.body