Error getting a userToken for Apple Music SDK with JWT

故事扮演 提交于 2019-12-12 12:17:20

问题


I'm trying unsuccessfully to get a userToken for Apple Music SDK using the developerToken from JWT. I've used pelauimagineering/apple-music-token-generator and I could get a valid and static userToken. But apple recommend to make dynamic, so I'm trying to use JWT again.

Someone can tell me please what's wrong with my code? Thank you

func fetchDeveloperToken() -> String? {
   func fetchDeveloperToken() -> String? {
    let iat = Date().timeIntervalSince1970
    let days = TimeInterval(24*60*60*120) //120 days
    let exp = TimeInterval(iat + days)
    let kid = "TBESJXXXXX"
    let iss = "KQ6Z6XXXXX"
    let alg = "ES256"
    let secret = "MIGTAgEAMBMGByqEU7ZHQsoVfmKCCxS5W6BnCgCgYIKoZIzj0AAQcggNoN7dTkNG/8timkkf+Z2toogAqN41YgOXXXXXXXXXXXXXXXXXXsecretkey"
    let header:[AnyHashable:Any] = ["alg":alg, "kid":kid]
    let payload:[AnyHashable:Any] = ["iss": iss,
                                     "iat": iat,
                                     "exp": exp]
    let algorithm256 = JWTAlgorithmHS256()
    return JWT.encodePayload(payload, withSecret: secret, withHeaders: header, algorithm: algorithm256)
}

回答1:


Apple requires you to use the ES256 algorithm, not HS256, I ran into the same issue too. The JWT libray that you're using doesn't support ES256 as you can see here. The only other library on iOS that is listed that supports it is this one



来源:https://stackoverflow.com/questions/46721314/error-getting-a-usertoken-for-apple-music-sdk-with-jwt

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!