[GH-ISSUE #354] Status Code : 400 #225

Closed
opened 2026-03-03 16:46:49 +03:00 by kerem · 1 comment
Owner

Originally created by @megifernanda on GitHub (Mar 21, 2017).
Original GitHub issue: https://github.com/OAuthSwift/OAuthSwift/issues/354

Description:

hello sir im so sorry, if i always make issue here, but now im really stuck
im success get token and build authentication login with oauth

and if im running this code, i already pass oauth_token to paramater login with identifier and password. but nothing happen redirect

i got output debug like this
screen shot 2017-03-21 at 10 14 30 am

      `import UIKit
       import OAuthSwift

     class ViewController: UIViewController {

@IBOutlet weak var passwordTxt: UITextField!
@IBOutlet weak var phonenumberTxt: UITextField!

var oauthswift: OAuth1Swift?
let dataShared = UserDefaults.standard

let fileUrl = NSURL(string: "8villages://app/oauth-callback")

override func viewDidLoad() {
    super.viewDidLoad()
}

@IBAction func doLogin(_ sender: Any) {
 var is8VillagesInstalled: Bool = {
        let appUrl = URL(string: "8villages://app")
        return UIApplication.shared.canOpenURL(appUrl!)
    }()
    
    self.oauthswift = OAuth1Swift.init(consumerKey: "********",
                                       consumerSecret: "********",
                                       requestTokenUrl: "https://oauth.8villages.com/tokens/request-token",
                                       authorizeUrl: "8villages://app/?oauth_token_secret=",
                                       accessTokenUrl: "https://accounts.8villages.com/tokens/access-token")
    self.oauthswift?.authorizeURLHandler = OAuthSwiftOpenURLExternally.sharedInstance
    self.oauthswift?.allowMissingOAuthVerifier = true
    
    self.oauthswift?.postOAuthRequestToken(
        callbackURL: fileUrl as! URL,
        success: { credentials, response, parameters in
            print("credentials", credentials)
            print("response =", response!)
            print("parameters =", parameters)
            
            let phonenumber = self.phonenumberTxt.text
            let password = self.passwordTxt.text
            if(phonenumber == "" || password == "")
            {
                return
            }
            
            let token = parameters["oauth_token"]
            self.doLogin(phonenumber!, password!, token! as! String)
            
            
    }, failure: { error in
        print("the error is", error.description, error.errorCode)
    });
    }

func doLogin(_ number:String, _ pswrd:String, _ tkn:String){
  let url = URL(string: "https://accounts.8villages.com/authentication")
 let session = URLSession.shared
 let request = NSMutableURLRequest(url: url!)
request.httpMethod = "POST"

let paramToSend = "identifier=" + number + "&password=" + pswrd + "&requestToken" + tkn
    print(number)
    print(pswrd)
    print(tkn)
request.httpBody = paramToSend.data(using: String.Encoding.utf8)

let task = session.dataTask(with: request as URLRequest, completionHandler: {
    (data, response, error) in
    
    print (data!)
    print (response!)
    print ("the error is", error.debugDescription)
    
    
    guard let _:Data = data else
    {
        return
    }
    
    let json:Any?
    do {
        
        json = try JSONSerialization.jsonObject(with: data!, options: [])
    }
    catch {
        return
    }
    
    guard let server_response = json as? NSDictionary else {
        return
    }
    
    if let data_block = server_response["data"] as? NSDictionary {
        if let session_data = data_block["session"] as? String {
            let preference = UserDefaults.standard
            preference.set(session_data, forKey: "session")
            
            DispatchQueue.main.async(
                execute:self.LoginDone
            )//
            
        }
    }
})

task.resume()
         }
 func LoginDone() {
            self.performSegue(withIdentifier: "loginView", sender: self)
         }
         }`

OAuth Provider (Twitter, Github, ..):

8 villages

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: (i don't know)

Xcode version:

  • 8.0 (Swift 3.0)

  • 8.0 (Swift 2.3)

  • 7.3.1

  • other: (Please fill in the version you are using.)

  • objective c

Originally created by @megifernanda on GitHub (Mar 21, 2017). Original GitHub issue: https://github.com/OAuthSwift/OAuthSwift/issues/354 ### Description: hello sir im so sorry, if i always make issue here, but now im really stuck im success get token and build authentication login with oauth and if im running this code, i already pass oauth_token to paramater login with identifier and password. but nothing happen redirect i got output debug like this <img width="741" alt="screen shot 2017-03-21 at 10 14 30 am" src="https://cloud.githubusercontent.com/assets/25347608/24131123/406d0550-0e1f-11e7-8a1c-a9e306c9af4d.png"> `import UIKit import OAuthSwift class ViewController: UIViewController { @IBOutlet weak var passwordTxt: UITextField! @IBOutlet weak var phonenumberTxt: UITextField! var oauthswift: OAuth1Swift? let dataShared = UserDefaults.standard let fileUrl = NSURL(string: "8villages://app/oauth-callback") override func viewDidLoad() { super.viewDidLoad() } @IBAction func doLogin(_ sender: Any) { var is8VillagesInstalled: Bool = { let appUrl = URL(string: "8villages://app") return UIApplication.shared.canOpenURL(appUrl!) }() self.oauthswift = OAuth1Swift.init(consumerKey: "********", consumerSecret: "********", requestTokenUrl: "https://oauth.8villages.com/tokens/request-token", authorizeUrl: "8villages://app/?oauth_token_secret=", accessTokenUrl: "https://accounts.8villages.com/tokens/access-token") self.oauthswift?.authorizeURLHandler = OAuthSwiftOpenURLExternally.sharedInstance self.oauthswift?.allowMissingOAuthVerifier = true self.oauthswift?.postOAuthRequestToken( callbackURL: fileUrl as! URL, success: { credentials, response, parameters in print("credentials", credentials) print("response =", response!) print("parameters =", parameters) let phonenumber = self.phonenumberTxt.text let password = self.passwordTxt.text if(phonenumber == "" || password == "") { return } let token = parameters["oauth_token"] self.doLogin(phonenumber!, password!, token! as! String) }, failure: { error in print("the error is", error.description, error.errorCode) }); } func doLogin(_ number:String, _ pswrd:String, _ tkn:String){ let url = URL(string: "https://accounts.8villages.com/authentication") let session = URLSession.shared let request = NSMutableURLRequest(url: url!) request.httpMethod = "POST" let paramToSend = "identifier=" + number + "&password=" + pswrd + "&requestToken" + tkn print(number) print(pswrd) print(tkn) request.httpBody = paramToSend.data(using: String.Encoding.utf8) let task = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) in print (data!) print (response!) print ("the error is", error.debugDescription) guard let _:Data = data else { return } let json:Any? do { json = try JSONSerialization.jsonObject(with: data!, options: []) } catch { return } guard let server_response = json as? NSDictionary else { return } if let data_block = server_response["data"] as? NSDictionary { if let session_data = data_block["session"] as? String { let preference = UserDefaults.standard preference.set(session_data, forKey: "session") DispatchQueue.main.async( execute:self.LoginDone )// } } }) task.resume() } func LoginDone() { self.performSegue(withIdentifier: "loginView", sender: self) } }` ### OAuth Provider (Twitter, Github, ..): 8 villages ### OAuth Version: - [x] Version 1 - [ ] Version 2 ### OS (Please fill the version) : - [x] iOS : - [ ] OSX : - [ ] TVOS : - [ ] WatchOS : ### Installation method: - [x] Carthage - [ ] CocoaPods - [ ] Manually ### Library version: - [ ] head - [ ] v1.0.0 - [ ] v0.6 - [x] other: (i don't know) ### Xcode version: - [x] 8.0 (Swift 3.0) - [ ] 8.0 (Swift 2.3) - [ ] 7.3.1 - [ ] other: (Please fill in the version you are using.) - [ ] objective c
kerem closed this issue 2026-03-03 16:46:50 +03:00
Author
Owner

@phimage commented on GitHub (Mar 21, 2017):

please do not open anymore issue, go to stackoverflow...
learn to use github... to repopen an issue, to respond to question or I will report an abuse

#353

#352

#350

#349

<!-- gh-comment-id:288033039 --> @phimage commented on GitHub (Mar 21, 2017): please do not open anymore issue, go to stackoverflow... learn to use github... to repopen an issue, to respond to question or I will report an abuse #353 #352 #350 #349
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/OAuthSwift#225
No description provided.