Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using OAuth1 with .Post request does not work #34

Open
OmarAl-Qadri opened this issue Jun 4, 2020 · 0 comments
Open

Using OAuth1 with .Post request does not work #34

OmarAl-Qadri opened this issue Jun 4, 2020 · 0 comments

Comments

@OmarAl-Qadri
Copy link

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant