File: app.psgi

package info (click to toggle)
libwebservice-dropbox-perl 2.10-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 360 kB
  • sloc: perl: 885; makefile: 2
file content (45 lines) | stat: -rw-r--r-- 892 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
use strict;
use warnings;
use Amon2::Lite;
use WebService::Dropbox;

__PACKAGE__->load_plugins('Web::JSON');

my $key = $ENV{DROPBOX_APP_KEY};
my $secret = $ENV{DROPBOX_APP_SECRET};
my $dropbox = WebService::Dropbox->new({ key => $key, secret => $secret });

my $redirect_uri = 'http://localhost:5000/callback';

get '/' => sub {
    my ($c) = @_;

    my $url = $dropbox->authorize({ redirect_uri => $redirect_uri });

    return $c->redirect($url);
};

get '/callback' => sub {
    my ($c) = @_;

    my $code = $c->req->param('code');

    my $token = $dropbox->token($code, $redirect_uri);

    my $account = $dropbox->get_current_account || { error => $dropbox->error };

    return $c->render_json({ token => $token, account => $account });
};

__PACKAGE__->to_app();

__DATA__

@@ index.tt
<!doctype html>
<html>
    <body>
        <h1>Hello</h1>
        [% res %]
    </body>
</html>