title: How to create a JWT for use with Apple Music
body: <p>Im trying to create a developer token that is a ES256 JWT to use for Apple Music authentication. (<a href="https://developer.apple.com/library/content/documentation/NetworkingInternetWeb/Conceptual/AppleMusicWebServicesReference/SetUpWebServices.html#//apple_ref/doc/uid/TP40017625-CH2-SW1" rel="noreferrer">Here</a>)</p>
  
  <p>Im using ruby and the JWT gem but after creating the token I get a 401 error when authenticating with Apple Music</p>
  
  <pre><code>    require 'jwt'
  
      payload = {:iss =&gt; 'CapExdTeam', :iat =&gt; '1497335982', :exp =&gt; '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 =&gt; "CapExedKid", :alg =&gt; "ES256" }
      puts token
  
      `curl -v -H 'Authorization: Bearer #{token}' "https://api.music.apple.com/v1/catalog/us/songs/203709340"
  </code></pre>
  
  <p>Im using the sample private key to simulate 429 error just for illustration purposes</p>