How to get the Music User Token?

After thoroughly scouring the internet numerous times, I came to the realization that Apple has not documented their User Authentication flow. Instead, developers are often directed to use their JavaScript solution, which proves to be insufficient and impractical for many projects.

Could we please request a comprehensive documentation outlining the process of generating a Music User Token from the Developer Token? This would greatly benefit developers seeking to integrate Apple Music functionality into their projects.

Replies

The only way officially is to use Apple's client libraries, which isn't great, unless you want to violate the agreements you signed with Apple and be at the mercy of Apple never changing the system, you're just going to have to use the client library.

So, you can use MusicKit.js like so:

const MusicKit = new Promise((r) => {
    if (window['MusicKit']) return r(window['MusicKit']);
    window.addEventListener("musickitloaded", () => r(window['MusicKit']));
}) as Promise<typeof window['MusicKit']>;

const MKInstance = MusicKit.then((MusicKit) => MusicKit.configure({
    developerToken: await getAppleMusicKey(),
    app: {
        name: "My Cool App",
    }
}))

let mut = MKInstance.then((mk) => mk.authorize())

// `mut` will be a promise that resolves with the user's MUT once the user logs in to the `MKInstance`