PouleR / apple-music-api

PHP Wrapper for the Apple Music API
39 stars 13 forks source link

How to request Authorization for User Token #2

Closed njsa04 closed 5 years ago

njsa04 commented 5 years ago

Hi is there a way to request the authorization from a User so that we can get their User Token? Or does this code require you to pass it in or hard code it?

Thanks

PouleR commented 5 years ago

To retrieve a User Music Token from Apple you currently need to use the Musickit JS Library that Apple provides. They do not support an authentication method like oAuth2.

See also: https://developer.apple.com/documentation/musickitjs

You can use this to log the token to your console

<script>
document.addEventListener('musickitloaded', function() {
  // MusicKit global is now defined
  music = MusicKit.configure({
    developerToken: '',
    app: {
      name: 'test',
      build: '1978.4.1'
    }
  });

  music.authorize().then(musicUserToken => {
    console.log(musicUserToken);
  });
});
</script>
njsa04 commented 5 years ago

Thanks I got it !