I'm building a music streaming application using Music Kit JS. The frontend uses Vue and the backend uses Express.
That said I had a few questions. I'm trying to generate a token that can be used with the music player configuration. This is how I have it setup currently:
const mk = await (window as any).MusicKit;
musicKit.value = await mk.configure({
developerToken: "DevTokenExample",
userToken:"userTokenExample",
app: {
name: "Apple Streaming Example",
build: "1.0.0",
},
});
I've omitted my developer token and user token. I'm able to stream music just fine, but it plays "previews" of the songs.
I have a login system setup for Apple OAuth authentication using this process: https://developer.apple.com/documentation/sign_in_with_apple/sign_in_with_apple_js
And all that works fine, I can get tokens and everything. I tried using the access_token as the userToken in the music kit configuration and the player still plays the previews of the songs.
I also used the id_token for the userToken to see if that would make a difference and it didn't do anything different, still played the previews.
To clarify, yes the account used is signed up to Apple Music.
Since that didn't work, I then used the "musicKit.authorize()" method which gave me a popup and I was trying to log in like that. Once I added in my 2FA code it just says there was an error connecting and I see in the URL an "UNABLE TO VERIFY JWT".
The few posts regarding that issue don't seem to have any fixes.
My questions are:
-
Can I use the Sign In With Apple Rest API method shown for the music kit user token?
-
If I can't use the Rest API method, how do I resolve the JWT error when using musicKit.authorize()?
Ok as I suspected the extra "aud" and "sub" when creating the JWT was causing the issue, at least that's the way it seems while testing. I recreated the developer token without them and used that for the music player and logged in with an account that has a subscription to Apple Music and it worked the first time with no issue. I will consider this solved and will also update my Feedback Assistance ticket as well. Thanks for the help!