我试图创建一个开发人员令牌,这是一个用于Apple Music身份验证的ES256 JWT. (
Here)
我使用ruby和JWT gem,但在创建令牌后,我在使用Apple Music进行身份验证时出现401错误
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错误仅用于说明目的