-
I am really stuck with this, trying to figure out how to create a JWT for Apple Music Kit. It says:
More here: https://developer.apple.com/documentation/applemusicapi/getting_keys_and_creating_tokens So my attempt was just following the documentation and replace a few things that are required for Apple, but I always get const jwt = new EncryptJWT({})
.setProtectedHeader({
kid: 'XXXXXXX',
alg: 'ES256',
crv: 'P-256',
})
.setIssuer('XXXXXXX')
.setIssuedAt(now.unix())
.setExpirationTime(now.add(1, 'week').unix())
.encrypt(privateKey) The format of the private key is: -----BEGIN PRIVATE KEY-----
KEY
-----END PRIVATE KEY----- Much appreciate and hints! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
Apple's documentation says encrypt, but they mean sign. ES256 is a DSA scheme, not encryption one. The tokens are signed, not encrypted. You want to use the You'll also have to pass the private key through Node's const keyObject = crypto.createPrivateKey(privateKey); // cache this value, you'll be re-using it.
const jwt = new SignJWT({})
.setProtectedHeader({
kid: 'ABC123DEFG',
alg: 'ES256',
})
.setIssuer('DEF123GHIJ')
.setIssuedAt()
.setExpirationTime('1 week')
.sign(keyObject) |
Beta Was this translation helpful? Give feedback.
Apple's documentation says encrypt, but they mean sign. ES256 is a DSA scheme, not encryption one. The tokens are signed, not encrypted.
You want to use the
jose/jwt/sign
module instead.You'll also have to pass the private key through Node's
crypto.createPrivateKey
to end up with aKeyObject
instance that is required as input.