OAuthSwift / OAuthSwiftAlamofire

Utility method to sign Alamofire request
MIT License
104 stars 38 forks source link

Using OAuth1 with .Post request does not work #34

Open OmarAl-Qadri opened 4 years ago

OmarAl-Qadri commented 4 years ago

I get this response from the server when using OAuth with .post request

{ code = "woocommerce_rest_authentication_error"; data = { status = 401; }; message = "Invalid signature - provided signature does not match."; }


public func fetchObjectWithOAuth(type: APIMethodType, params: KBHTTPParameters? = nil, handler: @escaping (T?, _ error: AlertMessage?)->()) where T: Codable {

    session = SessionManager( configuration: .default )
    session?.adapter = oauthswift.requestAdapter
    self.session.request(type.url, method: type.httpMethod, parameters: params, encoding: URLEncoding.default,headers: type.headers).responseJSON { data in
                            switch data.result {
                            case .success(let value):
                                print("The value is : \n\(value)")
                                let decoder = JSONDecoder()

                                guard let jsonData = data.data else {
                                    handler(nil, AlertMessage(title: NetworkingStrings.baseErrorTitle.localized, body: NetworkingStrings.baseErrorMessage.localized))
                                    break
                                }

                                do {
                                    let result = try decoder.decode(T.self, from: jsonData)
                                    handler(result, nil)
                                }
                                catch {
                                    print("JSON SERIALIZATION error!: \(error)")
                                    handler(nil, AlertMessage.dataParseErrorAlertMessage)
                                }
                                break
                            case .failure(let error):
                                //handler(nil, self.parseApiError(data: data.data))
                                handler(nil, AlertMessage(title: NetworkingStrings.baseErrorTitle.localized, body: error.localizedDescription))
                                break
                            }
    }
}

Note: It works for other request types (.GET , .PUT ,.DELETE)