如何创建用于Apple Music的JWT [英] How to create a JWT for use with Apple Music

查看:78
本文介绍了如何创建用于Apple Music的JWT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建开发者令牌,该令牌是用于Apple Music身份验证的ES256 JWT. (

Im trying to create a developer token that is a ES256 JWT to use for Apple Music authentication. (Here)

我正在使用ruby和JWT gem,但是在创建令牌后,通过Apple Music进行身份验证时出现401错误

Im using ruby and the JWT gem but after creating the token I get a 401 error when authenticating with Apple Music

    require 'jwt'

    payload = {:iss => 'CapExdTeam', :iat => '1497335982', :exp => '1513112982'}

    priv = "-----BEGIN PRIVATE KEY-----
MIGTAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBHkwdwIBAQQgU208KCg/doqiSzsVF5sknVtYSgt8/3oiYGbvryIRrzSgCgYIKoZIzj0DAQehRANCAAQfrvDWizEnWAzB2Hx2r/NyvIBO6KGBDL7wkZoKnz4Sm4+1P1dhD9fVEhbsdoq9RKEf8dvzTOZMaC/iLqZFKSN6
-----END PRIVATE KEY-----"
    ecdsa_key = OpenSSL::PKey::EC.new(priv)

    token = JWT.encode payload, ecdsa_key, 'ES256', { :kid => "CapExedKid", :alg => "ES256" }
    puts token

    `curl -v -H 'Authorization: Bearer #{token}' "https://api.music.apple.com/v1/catalog/us/songs/203709340"

我只是使用示例私钥来模拟429错误,只是出于说明目的

Im using the sample private key to simulate 429 error just for illustration purposes

推荐答案

我使用了此脚本,并且效果很好 https://github.com/pelauimagineering/apple-music-token-generator

I used this script and it works perfectly https://github.com/pelauimagineering/apple-music-token-generator

这篇关于如何创建用于Apple Music的JWT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆