无法加载模块:CTLS

时间:2017-06-12 10:33:19

标签: ios swift

我导入JWT(使用.Package(网址:“https://github.com/vapor/jwt.git”,majorVersion:1))

enter image description here

项目可以构建和运行。但是当我查看CTLS时,Xcode显示“无法加载模块:CTLS”。我不知道为什么。

与此同时,我创造的JWT似乎不对。这是我的代码:

import JWT
import Vapor

get("token") { req in
let algValue = StructuredData.string("ES256")
let kidValue = StructuredData.string("CapExedKid")
let headerData = StructuredData.object(["alg":algValue,"kid":kidValue])
let header = JSON.init(headerData)
let issValue = StructuredData.string("CapExdTeam")
let sec = Int(Date().timeIntervalSince1970)
let iatValue = StructuredData.number(StructuredData.Number(sec))
let expValue = StructuredData.number(StructuredData.Number(sec+1000000))
let claimsData = StructuredData.object(["iss":issValue,"iat":iatValue,"exp":expValue])
let claims = JSON.init(claimsData)
let url = URL.init(fileURLWithPath: "/Users/aamac/Desktop/HelloWorld/AuthKey_demoKey.p8")
let data = try Data.init(contentsOf: url)
let signer = ES256.init(key: data.makeBytes())
let jwt = try JWT.init(headers: header, payload: claims, signer: signer)
let token = try jwt.createToken() 
return token }

我使用令牌来执行身份验证请求,Apple Music API说,我有一个http状态代码500 .. 我在终端输入: 卷曲-v -H'授权:持票人[开发人员令牌]'“https://api.music.apple.com/v1/catalog/us/songs/203709340” 得到了500 ..

但是我使用Python库来获取令牌并在终端中执行请求,它有效,所以我怀疑swift中的JWT有某种问题......谁能告诉我?

1 个答案:

答案 0 :(得分:1)

我遇到了类似的问题(https://github.com/vapor/jwt/issues/47)。在我初始化签名者时,对我有用的是使用data.bytes.base64Decoded而不是data.makeBytes()