i am using this library for Uber Authetication
https://developer.uber.com/v1/auth/
I have done like this
func doOAuthUber(){
let oauthswift = OAuth2Swift(
consumerKey: "fXfXXXXXXXUo9vtKzobXXXXXUDO",
consumerSecret: "e5XXXXXXXq2w63qz9szEx7uXXXXXXo03W",
authorizeUrl: "https://login.uber.com/oauth/authorize",
accessTokenUrl: "https://login.uber.com/oauth/token",
responseType: "code"
)
var originalString = "jamesappv2://oauth/callback"
var encodedCallBackUrl = originalString.stringByAddingPercentEncodingWithAllowedCharacters(.URLHostAllowedCharacterSet())
println("encodedCallBackUrl: \(encodedCallBackUrl)")
let state: String = ""
oauthswift.authorizeWithCallbackURL( NSURL(string: encodedCallBackUrl!)!, scope: "request%20history", state: state, success: {
credential, response in
println(credential.oauth_token)
self.personalDriverLoader.stopAnimating()
}, failure: {(error:NSError!) -> Void in
self.personalDriverLoader.stopAnimating()
println(error.localizedDescription)
})
}
but getting this response HTTP Status 401: Unauthorized, Response: {"error": "invalid_client"}
I have triple checked that my client_id (consumerKey) and secret (consumerSecret) are correct. What I have done wrong here
Update:1
this is wired I changed responseType: "code" to responseType: "token" and it worked Got My access token. but I am getting an other issue now
now when ever I try to call the request endpoint api
using below code
@IBAction func btnRequestUberdidClicked(sender: AnyObject) {
self.callRequestAPI("https://sandbox-api.uber.com/v1/requests")
}
func callRequestAPI(url:String){
var configuration = NSURLSessionConfiguration.defaultSessionConfiguration()
var session = NSURLSession(configuration: configuration)
let params:[String: AnyObject] = [
"product_id" : selectedUberProductId,
"start_latitude" : start_lat,
"start_longitude" : start_lng,
"end_latitude" : end_lat,
"end_longitude" : end_lng]
appDelegate.oauthswift.client.post(url, parameters: params,
success: { data, response in
let dataString = NSString(data: data, encoding: NSUTF8StringEncoding)
println("Success")
println(data)
println(response)
}, failure: {(error:NSError!) -> Void in
println("Error")
println(error)
})
}
I am getting this response
Error Domain=NSURLErrorDomain Code=401 "HTTP Status 401: Unauthorized, Response: {"message":"Invalid OAuth 2.0 credentials provided.","code":"unauthorized"}" UserInfo=0x1c563220 {NSLocalizedDescription=HTTP Status 401: Unauthorized, Response: {"message":"Invalid OAuth 2.0 credentials provided.","code":"unauthorized"}, Response-Headers=<CFBasicHash 0x1c578c40 [0x35305710]>{type = immutable dict, count = 7,
entries =>
1 : x-xss-protection = <CFString 0x1ae2fc60 [0x35305710]>{contents = "1; mode=block"}
4 : Server = <CFString 0x1acc24c0 [0x35305710]>{contents = "nginx"}
5 : Content-Type = <CFString 0x1c4d0020 [0x35305710]>{contents = "application/json"}
6 : Content-Length = <CFString 0x1c4b70b0 [0x35305710]>{contents = "75"}
8 : Date = <CFString 0x1c4ed4b0 [0x35305710]>{contents = "Wed, 06 May 2015 12:46:51 GMT"}
10 : Strict-Transport-Security = <CFString 0x1c225cb0 [0x35305710]>{contents = "max-age=31536000; includeSubDomains; preload"}
11 : x-uber-app = <CFString 0x1c49a6b0 [0x35305710]>{contents = "uberex-sandbox"}
}
}