Generating Developer Token

I'm trying to create a web app that will authorise users and then let them manipulate their Apple Music accounts but I've fallen at the first hurdle.


I'm having the same issue that this gent had https://forums.developer.apple.com/message/314683 but sadly his solution isn't working for me.


I'm using the following code to generate tokens and it is spitting out strings...


"use strict";

const fs      = require("fs");
const jwt     = require("jsonwebtoken");

const privateKey = fs.readFileSync("AuthKey.p8").toString();
const teamId     = "blah";
const keyId      = "blah";

const jwtToken = jwt.sign({}, privateKey, {
algorithm: "ES256",
expiresIn: "180d",
issuer: teamId,
header: {
  alg: "ES256",
  kid: keyId
}
});

console.log(jwtToken);


...but authorisation returns the folliowing error:

Problem Connecting

There may be a network issue.


Try Again


The URL contains the string "error=ERROR_FAILED_TO_VERIFY_JWT" which, I assume, means my developer token is wrong. I've tried the following cURL request too and received a 401 Unauthorized error:
curl -v -H 'Authorization: Bearer [developer token]' "https://api.music.apple.com/v1/catalog/us/songs/203709340"