01 #!/usr/local/bin/perl -w 02 use strict; 03 use Mojolicious::Lite; 04 use Net::Dropbox::API; 05 use YAML qw(LoadFile DumpFile); 06 07 my $dev_key = "iyaiu823ajksgwf"; 08 my $dev_secret = "zlkj32lkj2kl3dp"; 09 my $listen = "http://localhost:8082"; 10 my($home) = glob '~'; 11 my $CFG_FILE = "$home/.dropbox.yml"; 12 13 my $CFG = {}; 14 $CFG = LoadFile( $CFG_FILE ) if 15 -f $CFG_FILE; 16 17 @ARGV = (qw(daemon --listen), $listen); 18 19 my $box = Net::Dropbox::API->new({ 20 key => $dev_key, 21 secret => $dev_secret, 22 }); 23 24 my $REQUEST_TOKEN; 25 my $REQUEST_SECRET; 26 27 ########################################### 28 get '/' => sub { 29 ########################################### 30 my ( $self ) = @_; 31 32 $box->callback_url( "$listen/callback" ); 33 $self->stash->{login_url} = $box->login; 34 35 $REQUEST_TOKEN = $box->request_token; 36 $REQUEST_SECRET = $box->request_secret; 37 } => 'index'; 38 39 ########################################### 40 get '/callback' => sub { 41 ########################################### 42 my ( $self ) = @_; 43 44 $box->auth({ 45 request_token => 46 $self->param('oauth_token'), 47 request_secret => 48 $REQUEST_SECRET 49 }); 50 51 $CFG->{ access_token } = 52 $box->access_token(); 53 $CFG->{ access_secret } = 54 $box->access_secret(); 55 56 DumpFile $CFG_FILE, $CFG; 57 58 $self->render_text( "Token saved.", 59 layout => 'default' ); 60 }; 61 62 app->start; 63 64 __DATA__ 65 ########################################### 66 @@ index.html.ep 67 % layout 'default'; 68 Login on dropbox.com 70 71 @@ layouts/default.html.ep 72 73
76 <%== content %> 7778 79