Add Apple Music integration for now playing

This commit is contained in:
2023-11-02 08:58:44 +11:00
parent c1d756ec6f
commit 4b6107188e
15 changed files with 183 additions and 0 deletions

View File

@@ -0,0 +1,29 @@
require "jwt"
module Admin
module Views
module AppleMusic
class Index < Admin::View
include Deps["settings"]
expose :developer_token do
authentication_payload = {
iss: settings.apple_music_team,
iat: Time.now.to_i, # Issue date
exp: Time.now.to_i + 3600 # Expiry of this token.
}
# The file we got from Apple
apple_music_secret = File.read(File.join(Hanami.app.root, "config", "AuthKey_#{settings.apple_music_key}.p8"))
private_key = OpenSSL::PKey::EC.new(apple_music_secret)
JWT.encode(
authentication_payload,
private_key,
'ES256',
kid: settings.apple_music_key
)
end
end
end
end
end