Passing Session id to rest client

122 views
Skip to first unread message

Avi

unread,
Sep 14, 2012, 5:12:42 AM9/14/12
to rubyonra...@googlegroups.com
Hello,

How can I pass session id through my rails application to a rest client through HTTParty or RestClient?


Thanks

Jordon Bedwell

unread,
Sep 14, 2012, 7:49:38 AM9/14/12
to rubyonra...@googlegroups.com
I would consider this a security problem, and a major one at that but
whatever who am I judge your bad security. You need to serialize the
object, I don't know about the default session handler but I think it
responds to load and dump and even if it doesn't you can always use
Marshal to Marshal the object but that means that the guy down the way
needs some of your code possibly to unmarshal it.

Avi

unread,
Sep 14, 2012, 8:08:11 AM9/14/12
to rubyonra...@googlegroups.com, envy...@gmail.com
So, here is what I am trying to do :-

login_response = RestClient.post 'Some URL', :userName => 'username', :password => 'password'  // Here I am logging in to the site.
puts "login_response"  // Here I am getting the response as an xml format which is a session_id

So for accessing the content after login, I need session id to perform CRUD operations.

search = RestClient.get 'URL after login to search a list'    // here need to pass the session id. Or any suggestions what need to do in this case ?

Robert Walker

unread,
Sep 14, 2012, 7:20:29 PM9/14/12
to rubyonra...@googlegroups.com
Avi wrote in post #1075999:
> So, here is what I am trying to do :-
>
> login_response = RestClient.post 'Some URL', :userName => 'username',
> :password => 'password' // Here I am logging in to the site.
> puts "login_response" // Here I am getting the response as an xml
> format
> which is a session_id
>
> So for accessing the content after login, I need session id to perform
> CRUD
> operations.
>
> search = RestClient.get 'URL after login to search a list' // here
> need
> to pass the session id. Or any suggestions what need to do in this case
> ?

I've handled clients like these in one of a few of ways:

1. Use a client implementation that supports HTTP cookies just like a
web browser does. Login the normal way and let the client manage passing
the cookie back to the server (just like a browser).

2. Use a token based client authentication mechanism where the token is
generated by the server with that token bound to the user account.
Something like what Pivotal Tracker does with their API tokens.

3. Use something like OAuth, which provides a way for external clients
to authenticate through the OAuth protocol (probably overkill for your
needs).

--
Posted via http://www.ruby-forum.com/.
Reply all
Reply to author
Forward
0 new messages