2

Using the Parse REST API, once I have authenticated a user with username and password, I get a session token. I store that session token in the user's cookie's, but how do I fetch a user with that session token?

My web app is in Ruby on Rails. I'm using gem parse-ruby-client.

Parse::User.authenticate('cooldude6', PASSWORD)

returns

{"username"=>"cooldude6", "createdAt"=>"2013-01-31T15:22:40.339Z", "objectId"=>"2bMfWZQ9Ob", "sessionToken"=>"zrGuvs3psdndaqswhf0smupsodflkqbFdwRs"}

How do I then use that sessionToken to retrieve the current user from Parse?

2 Answers 2

3

Either query the _User table (endpoint: /1/users) for the user with the "cooldude6" username, or get the user directly with its object id (endpoint: /1/users/2bMfWZQ9Ob). You'd only use the session token to authenticate REST API requests as the user via the X-Parse-SessionToken header, which would let you read and write data based on the user's ACL.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks Hector! Is there an equivalent to Parse.User.current() for the REST API? I thought I'd be able to use the sessionToken to retrieve that.
Keeping a local reference to the currentUser is a client side concept, so it doesn't really map well to the REST API.
It is X-Parse-Session-Token. Dash after session is important.
1

You can validate a session token by making a GET request to the /1/users/me endpoint with the token in the X-Parse-Session-Token header. I’m unfamiliar with that Ruby gem, but perhaps you could use one of its User queries?

However you make the request, Parse will return the full user object if the session token is still valid, or {"code":101,"error":"invalid session"} otherwise.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.