Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Sinatra Dropbox Oauth
require 'rubygems'
require 'erb'
require 'sinatra'
require 'dropbox'
configure do
enable :sessions
end
def authed?
redirect '/login' unless session[:dropbox_session]
dropbox_session = Dropbox::Session.deserialize(session[:dropbox_session])
redirect '/login' unless dropbox_session.authorized?
end
get '/' do
erb :index
end
get '/admin' do
authed?
erb :admin
end
get '/login' do
if params[:oauth_token] then
dropbox_session = Dropbox::Session.deserialize(session[:dropbox_session])
dropbox_session.authorize(params)
session[:dropbox_session] = dropbox_session.serialize # re-serialize the authenticated session
redirect '/admin'
else
dropbox_session = Dropbox::Session.new('app_key', 'app_secret')
session[:dropbox_session] = dropbox_session.serialize
redirect dropbox_session.authorize_url(:oauth_callback => "#{@env['rack.url_scheme']}://#{request.host_with_port}/login")
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.