This repository was archived by the owner on Mar 3, 2026. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ const jwt = require ( 'jsonwebtoken' )
2+
3+ /**
4+ *
5+ * @param {Object } credentials Apple Music credentials. Consists of a key containing MusicKit privileges, the team ID of developer account and the ID of the key
6+ * @param {string } credentials.key A valid key generated from developer console that has MusicKit permissions
7+ * @param {string } credentials.keyId ID of the credentials.key
8+ * @param {string } credentials.teamId ID of the team that credentials.key belongs to
9+ */
10+ const createJWT = ( credentials ) => {
11+ if ( ! credentials || ! credentials . key || ! credentials . teamId || ! credentials . keyId ) {
12+ throw new Error ( "No credentials supplied" )
13+ }
14+
15+ return jwt . sign ( { } , credentials . key , {
16+ algorithm : 'ES256' ,
17+ expiresIn : '180d' ,
18+ issuer : credentials . teamId ,
19+ header : {
20+ alg : 'ES256' ,
21+ kid : credentials . keyId
22+ }
23+ } ) ;
24+ }
25+
26+ module . exports . createJWT = createJWT
Original file line number Diff line number Diff line change 11{
22 "name" : " node-musickit-api" ,
3- "version" : " 2.1.0 " ,
3+ "version" : " 2.1.1 " ,
44 "description" : " A wrapper for the Apple Music API written in NodeJS" ,
55 "main" : " index.js" ,
66 "repository" : {
Original file line number Diff line number Diff line change 11const jwt = require ( 'jsonwebtoken' )
22const axios = require ( 'axios' )
33
4+ const { createJWT } = require ( "../../modules/createJWT" )
5+
46const rootPath = "https://api.music.apple.com/v1"
57let token
68let auth
@@ -21,15 +23,7 @@ class MusicKit {
2123 throw new Error ( "No credentials supplied" )
2224 }
2325
24- token = jwt . sign ( { } , credentials . key , {
25- algorithm : 'ES256' ,
26- expiresIn : '180d' ,
27- issuer : credentials . teamId ,
28- header : {
29- alg : 'ES256' ,
30- kid : credentials . keyId
31- }
32- } ) ;
26+ token = createJWT ( credentials )
3327
3428 this . updateAuth ( token )
3529 }
Original file line number Diff line number Diff line change 11const jwt = require ( 'jsonwebtoken' )
22const axios = require ( 'axios' )
3+ const { createJWT } = require ( "../../modules/createJWT" )
34
45const rootPath = "https://api.music.apple.com/v1"
56let token
@@ -29,15 +30,7 @@ class MusicKit {
2930 throw new Error ( "No credentials supplied" )
3031 }
3132
32- token = jwt . sign ( { } , credentials . key , {
33- algorithm : 'ES256' ,
34- expiresIn : '180d' ,
35- issuer : credentials . teamId ,
36- header : {
37- alg : 'ES256' ,
38- kid : credentials . keyId
39- }
40- } ) ;
33+ token = createJWT ( credentials )
4134
4235 this . updateAuth ( token , credentials . userToken )
4336 }
Original file line number Diff line number Diff line change 11const jwt = require ( 'jsonwebtoken' )
22const axios = require ( 'axios' )
3+ const { createJWT } = require ( "../../modules/createJWT" )
34
45const rootPath = "https://api.music.apple.com/v1"
56let token
@@ -18,15 +19,7 @@ class MusicKit {
1819 throw new Error ( "No credentials supplied" )
1920 }
2021
21- token = jwt . sign ( { } , credentials . key , {
22- algorithm : 'ES256' ,
23- expiresIn : '180d' ,
24- issuer : credentials . teamId ,
25- header : {
26- alg : 'ES256' ,
27- kid : credentials . keyId
28- }
29- } ) ;
22+ token = createJWT ( credentials )
3023
3124 this . updateAuth ( token )
3225 }
You can’t perform that action at this time.
0 commit comments