[GH-ISSUE #431] I am using OAuthSwift lib to call web services. We are using OAuth 1 at server side for authentication. But every time I call services it creates a new session at server side. by using Cookies Jar, my android app able to maintain sessio… #277

Closed
opened 2026-03-03 16:47:20 +03:00 by kerem · 1 comment
Owner

Originally created by @Rupesh1234fbbf on GitHub (Feb 1, 2018).
Original GitHub issue: https://github.com/OAuthSwift/OAuthSwift/issues/431

let oauthswift = OAuth1Swift(
consumerKey:"1xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
consumerSecret:"5xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
)
oauthswift.client.credential.oauthToken = "cxxxxxxxxxxxxxxxxxxxxxxxxx"
oauthswift.client.credential.oauthTokenSecret = "xxxxxxxxxxxxxxxxxxxxxxxx"

oauthswift.client.post(register_URL , parameters:requestDict, headers: ["Accept": "application/json", "Content-Type":"application/json"],success: { response in

    let dataString = response.string

    let data = dataString?.data(using: .utf8)
       do {
        //Parsing data & get the Array

    } catch let error as NSError {
        print("Failed to load: \(error.localizedDescription)")
        DispatchQueue.main.async {
            errorBlock(error.localizedDescription)
        }
    }
},
        failure: { error in
        print(error)
})

I also tried to keep the singleton pattern to keep oauthswift object same form to request but not helped. Also tried to set cookies in oAuthSwift Client as follows.

import Foundation
import OAuthSwift

class ClientHelper{

static var oauthswift:OAuth1Swift?

/* Create cookie and place in cookie storage */
static let cookieStorage = HTTPCookieStorage.shared
static func getInstance()->OAuth1Swift{


if(oauthswift == nil){
oauthswift = OAuth1Swift(
        consumerKey:"1xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
        consumerSecret:"5xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
     )
    oauthswift?.client.credential.oauthToken = "cxxxxxxxxxxxxxxxxxxxxxxxxx"
    oauthswift?.client.credential.oauthTokenSecret = "xxxxxxxxxxxxxxxxxxxxxxxx"
    oauthswift?.client.sessionFactory.configuration.httpCookieStorage = cookieStorage
   oauthswift?.client.sessionFactory.configuration.httpShouldSetCookies = true

}
    return oauthswift!;

}

}

Originally created by @Rupesh1234fbbf on GitHub (Feb 1, 2018). Original GitHub issue: https://github.com/OAuthSwift/OAuthSwift/issues/431 let oauthswift = OAuth1Swift( consumerKey:"1xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", consumerSecret:"5xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" ) oauthswift.client.credential.oauthToken = "cxxxxxxxxxxxxxxxxxxxxxxxxx" oauthswift.client.credential.oauthTokenSecret = "xxxxxxxxxxxxxxxxxxxxxxxx" oauthswift.client.post(register_URL , parameters:requestDict, headers: ["Accept": "application/json", "Content-Type":"application/json"],success: { response in let dataString = response.string let data = dataString?.data(using: .utf8) do { //Parsing data & get the Array } catch let error as NSError { print("Failed to load: \(error.localizedDescription)") DispatchQueue.main.async { errorBlock(error.localizedDescription) } } }, failure: { error in print(error) }) I also tried to keep the singleton pattern to keep oauthswift object same form to request but not helped. Also tried to set cookies in oAuthSwift Client as follows. import Foundation import OAuthSwift class ClientHelper{ static var oauthswift:OAuth1Swift? /* Create cookie and place in cookie storage */ static let cookieStorage = HTTPCookieStorage.shared static func getInstance()->OAuth1Swift{ if(oauthswift == nil){ oauthswift = OAuth1Swift( consumerKey:"1xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", consumerSecret:"5xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" ) oauthswift?.client.credential.oauthToken = "cxxxxxxxxxxxxxxxxxxxxxxxxx" oauthswift?.client.credential.oauthTokenSecret = "xxxxxxxxxxxxxxxxxxxxxxxx" oauthswift?.client.sessionFactory.configuration.httpCookieStorage = cookieStorage oauthswift?.client.sessionFactory.configuration.httpShouldSetCookies = true } return oauthswift!; } }
kerem closed this issue 2026-03-03 16:47:20 +03:00
Author
Owner

@phimage commented on GitHub (Feb 1, 2018):

Title too long
Issue template deleted
I close

<!-- gh-comment-id:362173230 --> @phimage commented on GitHub (Feb 1, 2018): Title too long Issue template deleted I close
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#277
No description provided.