Skip to the content

Apple Music User Token: Two Credentials, Two Failure Modes, One Resume Path

An Apple Music user token authenticates one listener. A developer token authenticates your app. Apple Music wants both, they come from different places, and they fail for different reasons with different repairs. MusicAPI's Apple Music page states the requirement directly: a paid Apple Developer Program membership, an ES256 developer token and a user token per listener. If your credential store keeps one row per user per provider across eleven streaming services, that row cannot record which half of Apple's pair stopped working. That is the gap this post closes.

An Apple Music user token authenticates one listener. A developer token authenticates your app. Apple Music wants both, they come from different places, and they fail for different reasons with different repairs. MusicAPI's Apple Music page states the requirement directly: a paid Apple Developer Program membership, an ES256 developer token and a user token per listener. If your credential store keeps one row per user per provider across eleven streaming services, that row cannot record which half of Apple's pair stopped working. That is the gap this post closes.

Here is the split in one view.

Developer tokenApple Music user token
Authenticatesyour app or serviceone listener
Comes froma JWT you sign with a Media Services private keylistener consent, one per listener
A bad credential affectsany service that uses that keythat listener's calls
Repaired bysigning again with key material you holdthe listener signing in again

What signs an Apple Music developer token

Apple's developer help is specific about the signing material. You use a Media Services private key to sign one or more developer tokens for MusicKit and other media services. The setup runs on Apple's side, not in your code: register a media identifier, enable each service you plan to use, create and download a private key with those media services enabled, then associate the key with the identifier. You then read the key identifier (kid) off the key and use it to create the JWT.

Two things follow for your architecture.

First, the developer token is produced by signing, not by an authorization round trip. Apple's instructions end with you building the JWT from the key and its identifier, which means this credential belongs with your secrets handling, not in the table where you keep listener credentials. Our notes on music API security and token storage cover that side.

Second, one line of the setup page belongs in a product review rather than a backend ticket: the identifier description is displayed as the app name to users when requesting access to Apple Music. Whatever somebody typed into that field months ago is the name your listener reads on the consent screen. If you are designing a re-consent prompt, and this post argues you should, read that string before you ship it.

The private key is the part you can lose permanently

A listener-side problem is recoverable by asking a human. A key problem can be permanent, so treat the.p8 as the most valuable file in the integration. Apple's key page is blunt about it: you can only download a key once, the key is saved as a text file with a.p8 file extension, and it is not saved in your developer account, so you will not be able to download it again. If the download button is disabled, somebody already took it.

Rotation has an order, and Apple spells it out. If you suspect a private key is compromised, first create a new private key associated with the media identifier, transition to it, and only then revoke the old one. That overlap is possible because you can associate two keys with each media identifier. Reverse the order and you learn the blast radius the hard way: a revoked key becomes invalid and affects any services that use the key.

So the runbook for Apple is short. Two keys live during a rotation. The new one signs. The old one gets revoked only after traffic has moved and you have watched the error rate for a while.

Telling a developer-side failure from a listener-side one

Your logs, not Apple's documentation, answer this at 03:00, so record the right fields before you need them. For every outbound Apple Music call, store the key identifier that signed the request, the listener identifier, the status code, and whether a renewal was attempted before the call. Those four fields turn a vague "Apple is failing" alert into a decision.

The shape of the incident does the rest of the work. One listener failing while thousands succeed is a listener-side problem, and no amount of retrying fixes it. Every listener failing at once, starting at the minute a deploy or a key rotation landed, points at the credential they all share. Treat the second case as an incident for your on-call engineer and the first as a prompt for a human who is not on your payroll.

On the MusicAPI side the boundary is explicit in the response. Renewal is automatic: MusicAPI keeps each user's music-service tokens and renews them for you, and its own library calls renew an expired token by themselves. When you force a renewal from your backend and the service refuses it, the answer is 401, and the user must sign in again. That 401 is the line between repair-in-software and repair-by-human. Everything above it should never reach a support queue. Our guide to OAuth token refresh across multiple music streaming APIs covers the generic loop; this is the branch at the end of it.

Where a long import actually dies

MusicAPI supports libraries of up to 200,000 items. A library that size does not move in one request, and it does not move in one minute, so the interesting question is not whether a credential ages out during the run. It is what your job does when one does.

The failure mode to avoid is a run that restarts. If your import job holds a credential in memory, pages until something returns an auth error, then marks the whole job failed, your listener starts from item zero after re-consent. Three design rules prevent that:

  • Checkpoint by item, not by job. Persist the cursor and the per-item outcome as you go, so a resumed run skips what already landed.
  • Key the job to the listener, not to the credential. The credential is replaceable. The listener identity survives re-consent.
  • Make writes idempotent at the item level, so a resumed page that overlaps the last committed page does not create duplicates.

This is also where the per-provider work piles up, and it is the part MusicAPI removes. MusicKit token handling, storefront selection and library-versus-catalogue ID mapping are handled server-side, and MusicAPI holds the Apple Music credentials and uses them solely to facilitate music transfers a listener has authorised, including token refresh and revocation. Matching across services resolves a track, album or artist to its Apple Music ID by ISRC or by text, with a confidence score. On the Apple Music API through one REST interface you get those with the same request and response shape as the other ten services.

One scheduling detail matters for resumes: transfers for one person run one after the other, never side by side. A second transfer waits until the first ends, then starts by itself. Do not queue a parallel retry job and expect it to overtake the stalled one.

Re-consent that resumes instead of restarting

Re-consent is a screen, and it should be the shortest screen in your product. The listener taps once and lands back where they were, with the import still holding its place.

The mechanics on MusicAPI: send the listener to the hosted Apple Music authorisation page with a whitelisted return URL.

https://app.musicapi.com/you/appleMusic/auth
?returnUrl=https://you.example/connected

They come back to your return URL with a base64 payload that decodes to this:

{
  "integrationUserUUID": "6a002d4b-f95b-471f-a27d-609a42e10cdb",
  "authModel": { "status": "success", "error": null },
  "integration": { "type": "appleMusic" }
}

That UUID unlocks every Apple Music user endpoint:

GET https://api.musicapi.com/api/6a002d4b-f95b-471f-a27d-609a42e10cdb/playlists
Authorization: Basic <clientId:clientSecret>

The design point is the identifier in the middle of that path. Public catalogue routes need no listener auth, and user routes are addressed by the userUUID returned from the auth callback. Store your import progress against that UUID and re-consent becomes a resume rather than a restart, because the thing your job state points at is the listener, not a credential string that changed. Details of the redirect and the callback live in the start sign-in docs.

Reading the raw token when you need it

Most integrations never touch raw provider credentials, and they should not. Read them only to call a service endpoint MusicAPI does not cover. When you do, it is a backend call with your Client Secret:

curl "https://api.musicapi.com/public/integrations/user/3f0b8c1e-6a4d-4c7a-9a55-2f1e7d9b0c11" \
  -u "$MUSICAPI_CLIENT_ID:$MUSICAPI_CLIENT_SECRET"

The response carries authData and authDataExpiresAt, which is when the access token expires in milliseconds since the epoch. Two properties of that payload are worth writing down. authData holds the service's credentials without the refresh token, and the fields depend on the service. When the token expires within one minute, MusicAPI renews it before it answers. So the expiry timestamp is there for your own bookkeeping, not as something you are expected to act on.

If you need the underlying Apple Music field that MusicAPI does not normalise in a transfer flow, passthrough gives you that listener's token. Read it from the backend, not the browser. For apps without a backend you ask for a one-time token by adding requestOneTimeToken=true to the sign-in URL and read it from the callback, and it is deliberately short-lived: call the connected-user endpoint with Authorization: Token <oneTimeToken> within 30 seconds. It is bound to the sign-in it came from, and for another connected user it answers 403.

If your sign-in returns to a web page, turn on the attach-only setting in the dashboard. When it is on, the one-time token of a sign-in that returns to an http or https return URL does not read authData. The token still proves the sign-in, and the raw credentials stay on your server. The setting is off by default, so this is an explicit decision somebody has to make. The raw tokens and refresh docs have the full matrix.

The one Apple write limit to design around

Auth design and write design meet in one place on Apple Music: a playlist you create is a playlist you cannot rename. Apple Music does not let third parties rename or re-describe an existing playlist. If a run stalls on an auth failure halfway through and your retry logic creates a second playlist with a provisional title, nothing cleans that title up later. Name playlists with their final title at creation time, and resume into the existing playlist rather than making a new one. The Apple Music API add to library post covers the write path in full.

FAQ

Do I need my own Apple Developer Program membership to use MusicAPI for Apple Music?

No. Going direct needs a paid Apple Developer Program membership, an ES256 developer token and a user token per listener. With MusicAPI you call one API with your own key, and MusicAPI handles the Apple Music side, including token refresh and revocation.

How long does an Apple Music integration take?

A sandbox key is instant, and reading a live library takes about an hour. Production integrations typically land in two to four engineering weeks.

Can I rehearse re-consent in the sandbox?

Yes, within the cap. The evaluation account allows five connected test listeners in total across services, not five per service.

Skip months of OAuth and per-provider SDK work. Sandbox keys are free and instant, and one API moves libraries between 11 streaming services: start with the connect users sign-in flow.