ERROR_FAILED_TO_VERIFY_JWT error when trying to link with Apple Music

I want to use Apple Music using MusicKit.

I've created MusicKit identifier and private key by following all the steps mentioned here: https://help.apple.com/developer-account/#/devce5522674

I have my Team ID, the Music key ID and the private key (.p8 file) with me.

I tried to generate the required JWT token by using many scripts that were mentioned in similar questions asked here, but none of them have worked so far. When I try to authenticate, I'm getting an error ERROR_FAILED_TO_VERIFY_JWT.


Ref: Codes I've tried to generate the JWT token from:But sadly, none of them worked and I had to post this question.

I have tried the sample Android app: https://developer.apple.com/download/more/?=Android%20MusicKit

After authentication, the page goes on with an infinite loader, which I believe must be because of the same error ERROR_FAILED_TO_VERIFY_JWT

Also tried with this HTML page:
Code Block
<html>
<head>
<meta name="apple-music-developer-token" content="the-JWT-token-generated-using-the-reference-links">
<meta name="apple-music-app-name" content="My App Name">
<meta name="apple-music-app-build" content="1978.4.1">
</head>
<body>
<button id="apple-music-authorize"></button>
<button id="apple-music-unauthorize"></button>
</body>
<script src="link-to-musickit.js"></script>
<script>
let music = MusicKit.getInstance();
music.player.play();
music.authorize().then(function() {
music.player.play();
});
music.authorize().then(function() {
music.api.library.albums.then(function(cloudAlbums) {
// user's cloudAlbums
});
});
</script>
</html>

Replies

A while ago I started developing a hobby web app and I created a NodeJS script (that uses the npm package jsonwebtoken) to generate my dev JWT and I used MusicKit in my web app with that generated dev JWT and also used Apple Music API and everything was working perfectly fine, and now I came back and wanted to continue the project from where I left off and I tried using the same code (I literally ran the same NodeJS file without changing anything, it already had the p8 file and the team ID and app key etc..) so I generated a new JWT with that script, and for the Apple Music API it's working as it should, but for some reason I can't use the JWT with the MusicKit for web... when I try to authorize the user it does open the authorization pop up window and after the user enters their Apple Music credentials and tries to login the pop up windows says there's an error and in the URL I can see an "error" query param with the value "ERROR_FAILED_TO_VERIFY_JWT"
IDK why this happens but I'm sure it's a bug, we should report it through the feedback app, but with my past experience with Apple Music API and MusicKit it is really buggy and cannot be relied for production just yet, also when submitting a ticket though the feedback app sometimes they reply within a day and other times I waited for almost a month with no response...
Post not yet marked as solved Up vote reply of 0132 Down vote reply of 0132
  • @0132 I am having the same issue. My application was connecting fine with MusicKit and has recently stopped working. At first I suspected it was related to the JWT I generate in Ruby, but I ran some tests and managed to call and get a successful response from an Apple Music API endpoint that doesn’t require the user token.

    I noticed the same const in the “error” query param, check your local/session storage (if applicable to your use case) and clear it all. By doing that, I got past the “failed to verify jwt” error and am now getting stuck on a 400 BadRequest on GetMusicUserToken (or something) API request from within MusicKit’s popup window.

    I will try a few more things and update this thread if I’m successful, just in case someone else is experiencing the same issue.

Add a Comment

Hello, @kartikeya_rokde

If you’re still able to reproduce this issue, would you mind filing a ticket on Feedback Assistant, including a HAR export from the browser’s Network Inspector? This will help us investigate this issue further.

For more information on using the Network Tab in the Safari Web Inspector, you can review the WebKit Network Tab Documentation and instructions on Enabling the Web Inspector.

any solutions here?

do you guys come up with any solution.? I am facing the same issue.