OAuthSwift: WordPress OAuth1 returns "No OAuth parameters supplied"
Description:
I’m running OAuth1 against wordpress but receiving 400 error code: “No OAuth parameters supplied”
requestError[Error Domain=NSURLErrorDomain Code=400 "HTTP Status 400: Bad Request, Response: No OAuth parameters supplied" UserInfo={NSErrorFailingURLKey=http://example.us/oauth1/request, NSLocalizedDescription=HTTP Status 400: Bad Request, Response: No OAuth parameters supplied, Response-Headers={
"Access-Control-Allow-Headers" = Authorization;
Connection = "keep-alive";
"Content-Type" = "text/html; charset=UTF-8";
Date = "Sat, 05 Nov 2016 14:13:54 GMT";
"Keep-Alive" = "timeout=15";
Server = nginx;
"Transfer-Encoding" = Identity;
}, OAuthSwiftError.response=<NSHTTPURLResponse: 0x600000032320> { URL: http://example.us/oauth1/request } { status code: 400, headers {
"Access-Control-Allow-Headers" = Authorization;
Connection = "keep-alive";
"Content-Type" = "text/html; charset=UTF-8";
Date = "Sat, 05 Nov 2016 14:13:54 GMT";
"Keep-Alive" = "timeout=15";
Server = nginx;
"Transfer-Encoding" = Identity;
} }, OAuthSwiftError.response.data=<4e6f204f 41757468 20706172 616d6574 65727320 73757070 6c696564>, Response-Body=No OAuth parameters supplied}]
Here is the test functions:
class ViewController: OAuthViewController {
// oauth swift object (retain)
var oauthswift: OAuthSwift?
lazy var internalWebViewController: WebViewController = {
let controller = WebViewController()
controller.view = UIView(frame: UIScreen.main.bounds) // needed if no nib or not loaded from storyboard
controller.delegate = self
controller.viewDidLoad() // allow WebViewController to use this ViewController as parent to be presented
return controller
}()
}
extension ViewController {
override func viewDidLoad() {
super.viewDidLoad()
// init now web view handler
let _ = internalWebViewController.webView
self.navigationItem.title = "OAuth"
let tableView: UITableView = UITableView(frame: self.view.bounds, style: .plain)
tableView.delegate = self
tableView.dataSource = self
self.view.addSubview(tableView)
self.doOAuthWordpress()
}
// MARK: Fitbit
func doOAuthWordpress(){
let oauthswift = OAuth1Swift(
consumerKey: "xxx", // Hard coded for now
consumerSecret: "yyy", // Hard coded for now
requestTokenUrl: "http://example.us/oauth1/request",
authorizeUrl: "http://example.us/oauth1/authorize",
accessTokenUrl: "http://example.us/oauth1/access"
)
self.oauthswift = oauthswift
oauthswift.authorizeURLHandler = getURLHandler()
let _ = oauthswift.authorize(
withCallbackURL: URL(string: "oauth-swift://oauth-callback/wordpress")!,
success: { credential, response, parameters in
self.showTokenAlert(name: "WPTesting", credential: credential)
},
failure: { error in
print(error.description)
}
)
}
// MARK: handler
func getURLHandler() -> OAuthSwiftURLHandlerType {
if internalWebViewController.parent == nil {
self.addChildViewController(internalWebViewController)
}
return internalWebViewController
}
func showTokenAlert(name: String?, credential: OAuthSwiftCredential) {
var message = "oauth_token:\(credential.oauthToken)"
if !credential.oauthTokenSecret.isEmpty {
message += "\n\noauth_toke_secret:\(credential.oauthTokenSecret)"
}
self.showAlertView(title: name ?? "Service", message: message)
}
func showAlertView(title: String, message: String) {
let alert = UIAlertController(title: title, message: message, preferredStyle: UIAlertControllerStyle.alert)
alert.addAction(UIAlertAction(title: "Close", style: UIAlertActionStyle.default, handler: nil))
self.present(alert, animated: true, completion: nil)
}
}
OAuth Provider (WordPress):
WP REST API - OAuth 1.0a Server
OAuth Version:
- Version 1
- Version 2
OS (Please fill the version) :
- iOS :
- OSX :
- TVOS :
- WatchOS :
Installation method:
- Carthage
- CocoaPods
- Manually
Library version:
- head
- v1.0.0
- v0.6
- other: (Please fill in the version you are using.)
Xcode version:
-
8.0 (Swift 3.0)
-
8.0 (Swift 2.3)
-
7.3.1
-
other: (8.1)
-
objective c
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 23 (9 by maintainers)
I got into the same situation where the server returns “No OAuth parameters supplied”.
If you made the same mistake I made, this should solve it: Make sure the “callback” url in your wordpress application settings (where you get the key / secret from) and the oauth1swift.authorize() -> withCallbackURL parameter matches.