class Slipsquare::Middleware::AskForCredentials

Ask for user credentials from the command line, then write them out.

Public Instance Methods

call(env) click to toggle source
# File lib/slipsquare/middleware/ask_for_credentials.rb, line 8
def call(env)

  say "If you dont know your app and secret key, try `slipsquare get-keys`"

  app_key = ask "Enter your App key:"
  secret_key = ask "Enter your Secret key:"

  Dropbox::API::Config.app_key    = app_key
  Dropbox::API::Config.app_secret = secret_key

  consumer = Dropbox::API::OAuth.consumer(:authorize)
  request_token = consumer.get_request_token
  say "Go to this url and click 'Authorize' to get the token:"
  say request_token.authorize_url, :green
  query  = request_token.authorize_url.split('?').last
  params = CGI.parse(query)
  token  = params['oauth_token'].first
  yes? "Once you authorize the app on Dropbox, type yes... "
  access_token  = request_token.get_access_token(:oauth_verifier => token)

  # Write the config file.
  env['config'].create_config_file(app_key, secret_key, access_token.token, access_token.secret)
  env['config'].reload!

  say "Credentials saved to ~/.slipsquare"

  @app.call(env)
end