Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting cookies/sessions #30

Closed
sajoku opened this issue Nov 4, 2013 · 2 comments
Closed

Setting cookies/sessions #30

sajoku opened this issue Nov 4, 2013 · 2 comments

Comments

@sajoku
Copy link
Contributor

sajoku commented Nov 4, 2013

I'm trying to authenticate against a backend but am not sure on how to implement setting the http_cookie. (I think it should be handled by afnetworking itself?). The authentication itself works and while the app stays in the foreground I am authenticated. When I close the app the session seems to be cleared.

AFMotion::Client.build_shared(Web.base_url) do
  header "Accept", "application/json"

  response_serializer :json
end

And in my request:

  AFMotion::Client.shared.get(url, data) do |response|
    blk.call(response)
  end

Or
AFMotion::Client.shared.post(url, data) do |response|
blk.call(response)
end

I can't figure out where to set the cookie header for the requests. Should I need to and if so where/how to configure this?

@clayallsopp
Copy link
Collaborator

You should google around about NSHTTPCookieStorage and AFNetworking

Maybe http://stackoverflow.com/questions/14387662/afnetworking-persisting-cookies-automatically ?

If you use AFMotion::SessionClient, you can use configure a NSURLSessionConfiguration to use a default cookie storage

@sajoku
Copy link
Contributor Author

sajoku commented Nov 4, 2013

Thanks @clayallsopp this was easier than I thought.
Fixed it with http://stackoverflow.com/questions/14387662/afnetworking-persisting-cookies-automatically .
Calling save cookies after authentication and load cookies on every subsequent request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants