Coder Social home page Coder Social logo

Comments (5)

pcantrell avatar pcantrell commented on May 22, 2024

Cookie-based auth in an API (as opposed to a web site) is unusual and somewhat unorthodox, so I wouldn’t want to build special handling for it directly into Siesta itself.

If you do need cookie handling, that’s a responsibility that’s best left to the underlying networking library plus your app-specific rules for allowing & storing cookies. You’d add your own beforeStartingRequest hook to add cookie headers before sending the request, then receive cookie headers on receiving the response. That could even make a nice little lib.

For examples of the code you’d need to put in the beforeStartingRequest hook, see:

https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/URLLoadingSystem/CookiesandCustomProtocols/CookiesandCustomProtocols.html
http://stackoverflow.com/questions/29596206/how-to-get-cookie-from-a-nsurlsession-with-swift

from siesta.

nabbestemmia avatar nabbestemmia commented on May 22, 2024

Thank you, I'll follow your advices; I haven't other options, since I don't own the server side

from siesta.

pcantrell avatar pcantrell commented on May 22, 2024

Yes, we often have to make things work well with the APIs we’re given.

I’ll close this for now, but please do ask if you hit a snag with your Siesta configuration. The basic structure will be something like this:

service.configure {
  addStoredCookiesTo($0.config.headers)

  $0.config.beforeStartingRequest {
    _, req in
    req.onSuccess {
      entity in
      storeCookiesFrom(entity.headers)
    }
  }
}
func addStoredCookiesTo(inout headers: [String:String]) {
  // for each stored cookie
    header[cookieKey] = formattedCookieValue
}

func storeCookiesFrom(headers: [String:String]) {
  // parse any cookie headers
  if newCookieDetected {
    // store cookie
    service.invalidateConfiguration() // crucial!
  }
}

from siesta.

nabbestemmia avatar nabbestemmia commented on May 22, 2024

Ok, thanks a lot!

from siesta.

reubenwalkerau avatar reubenwalkerau commented on May 22, 2024

@nabbestemmia did you solve this? I have the same requirement to receive and send back a cookie but can't get it to work.

from siesta.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.