module Dropbox::WebClient::Authentication

Public Instance Methods

authenticate() click to toggle source
# File lib/dropbox/web_client/authentication.rb, line 10
def authenticate
  get_login
  post_login

  @authenticated = true
end
authenticated?() click to toggle source
# File lib/dropbox/web_client/authentication.rb, line 6
def authenticated?
  @authenticated
end
ensure_authenticated() click to toggle source

TODO: Should keep in consideration the session expiration…

# File lib/dropbox/web_client/authentication.rb, line 18
def ensure_authenticated
  authenticate unless authenticated?
  true
end

Private Instance Methods

get_after_login_url() click to toggle source

This step might not be required, it’s just following the redirect which we got in the previous authentication step.

# File lib/dropbox/web_client/authentication.rb, line 54
def get_after_login_url
  response = RestClient.get(after_login_url, :cookies => current_cookies)
  
  # Get _subject_uid (hidden field in response HTML)
  parsed_response = ResponseParser.new(response.body, :html, :html)
  @subject_uid = parsed_response.response_data[:subject_uid]
  
  return response
end
get_login() click to toggle source

Gets the login URL and keeps the cookies, required to continue the authentication process

# File lib/dropbox/web_client/authentication.rb, line 27
def get_login
  response = RestClient.get(login_url)
  cookies.take response.cookies
  response
end
post_login() click to toggle source

Posts user credentials and keeps the returned cookies, this’ll start a user session.

# File lib/dropbox/web_client/authentication.rb, line 35
def post_login
  response = RestClient.post(post_login_url, {
    "t" => cookies.login_token,
    "login_email" => @email,
    "login_password" => @password
  }, {:cookies => cookies.all}) do |response, request, result, &block|
    if response.code == 200
      cookies.take response.cookies
      parsed_response = ResponseParser.new(response.body)
      @subject_uid = parsed_response.response_data["id"]
    else
      response.return!(request, result, &block)
    end
  end
  response
end
subject_uid() click to toggle source
# File lib/dropbox/web_client/authentication.rb, line 64
def subject_uid
  @subject_uid
end