MusicKit - Authorization failed: AUTHORIZATION_ERROR: Unauthorized

Hello,

I am having difficulties with configuring MusicKit correctly for my web app that I am building, seeking assistance with the issues I am having. Would greatly appreciate any help!

After allowing access to the following,

"Access Request media.mydomain.com would like to access Apple Music, media library, and listening activity for myemail'@icloud.com.",

I get a popup error that states, "Authorization failed. Please try again.".

Following is the information that is given in developer console:

[Error] Failed to load resource: the server responded with a status of 403 () (webPlayerLogout, line 0) [Error] Authorization failed: AUTHORIZATION_ERROR: Unauthorized (anonymous function) (media.mydomain.com:398)

Hi,

Was also looking into the JS stuff for my app. Did you create the tokens and enable access to MusicKit in your Dev Account?

-P

Hi _Pancras,

What I did was create an Identifier>Media ID as "media.com.mydomain", downloaded my MusicKit Key (created using the Media ID), then used script to generate token. Not really sure what to do from here, next step is to reach out to Apple support 🤷🏻‍♂️

Here is the script I am using to generate token:

// generate_token.js const jwt = require('jsonwebtoken'); const fs = require('fs');

// Adjust these to your Apple Developer details: const privateKeyPath = '/home/theloungeuser/AuthKey_mykey.p8'; // Path to the .p8 const teamId = 'myTeamID'; // Your Apple Developer Team ID const keyId = 'myKeyID'; // 10-char Key ID for MusicKit

// Read the private key const privateKey = fs.readFileSync(privateKeyPath, 'utf8');

// Generate Apple MusicKit dev token (valid max 180 days) const token = jwt.sign( { iss: teamId, iat: Math.floor(Date.now() / 1000), exp: Math.floor(Date.now() / 1000) + (60 * 60 * 24 * 180), // 180 days aud: 'appstoreconnect-v1' }, privateKey, { algorithm: 'ES256', header: { kid: keyId } } );

console.log(token);

MusicKit - Authorization failed: AUTHORIZATION_ERROR: Unauthorized
 
 
Q