Saat ini saya mencoba menggunakan sylius api menggunakan domain demo.sylius.com, saya telah mengautentikasi dengan benar dan mendapatkan token akses tanpa masalah tetapi ketika harus meneruskan token akses ke header otorisasi saya mengalami masalah dengan respon {
error = "access_denied";
"error_description" = "OAuth2 authentication required";
}
meskipun api berfungsi dengan baik melalui tukang pos, ini contoh kode saya
func getTotalProducts(page:String, completionHandler: @escaping (_ totalProducts: TotalProducts) -> Void){
let urlPath=APIManager.baseURL+"api/v2/products"
let headers = ["Content-Type":"application/json","Authorization":"Bearer \(token)","X-Authorization":"Bearer SampleToken","Auth":"Bearer SampleToken","auth":"Bearer SampleToken"]
var request = URLRequest(url: NSURL(string: urlPath)! as URL)
// Your request method type Get or post etc according to your requirement
request.httpMethod = "GET"
request.setValue("Bearer SampleToken", forHTTPHeaderField: "Authorization")
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
request.setValue("Bearer SampleToken", forHTTPHeaderField: "X-Authorization")
request.setValue("Bearer SampleToken", forHTTPHeaderField: "auth")
Alamofire.request(request)
.responseJSON { response in
switch(response.result){
case .success(let value):
print(value)
let totalProducts = Mapper<TotalProducts>().map(JSON: value as! [String : Any])!
completionHandler(totalProducts)
break
case .failure(let error):
print("something went wrong \(error.localizedDescription)")
break
}
}.session.finishTasksAndInvalidate()
}