I already have successfully got keychain for my token and passing it to AccessTokenAdapter class shown below. http127.0.0.1:8000/api2/projects/?format=json is passed as projectsURL.
class AccessTokenAdapter: RequestAdapter {
private let accessToken: String
init(accessToken: String) {
self.accessToken = accessToken
}
func adapt(_ urlRequest: URLRequest) throws -> URLRequest {
var urlRequest = urlRequest
// print("JWT \(accessToken)")
urlRequest.setValue("JWT \(accessToken)", forHTTPHeaderField: "Authorization")
return urlRequest
}
}
let sessionManager = SessionManager()
sessionManager.adapter = AccessTokenAdapter(accessToken: self.keychain["token"]!)
sessionManager.request(self.projectsURL, method: .get, encoding: JSONEncoding.default).responseJSON{ response in
switch response.result {
case .success:
print("yey I made it")
case .failure(let error):
print(error)
}
}
however, from print(error), my Xcode shows error like Error Domain=NSURLErrorDomain Code=-999 "cancelled" UserInfo={NSErrorFailingURLKey=http://127.0.0.1:8000/api2/projects/?format=json, NSLocalizedDescription=cancelled, NSErrorFailingURLStringKey=http127.0.0.1:8000/api2/projects/?format=json}
Any ideas?
Alamofire 4.0
Keychain
Xcode 8.1
Swift3
Using JWT for authentication
Using Postman with header, key = "Authentication", value = "JWT (token generated here)" works fine