-
Notifications
You must be signed in to change notification settings - Fork 7
/
oauth2_server_simple_jwt.pl
50 lines (40 loc) · 1.01 KB
/
oauth2_server_simple_jwt.pl
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
46
47
48
49
50
#!perl
use strict;
use warnings;
use Mojolicious::Lite;
use Mojo::JWT;
plugin 'OAuth2::Server' => {
jwt_secret => "Is it secret?, Is it safe?",
clients => {
TrendyNewService => {
client_secret => 'boo',
scopes => {
"post_images" => 1,
"annoy_friends" => 1,
},
},
}
};
group {
# /api - must be authorized
under '/api' => sub {
my ( $c ) = @_;
return 1 if $c->oauth;
$c->render( status => 401, text => 'Unauthorized' );
return undef;
};
any '/annoy_friends' => sub { shift->render( text => "Annoyed Friends" ); };
any '/post_image' => sub { shift->render( text => "Posted Image" ); };
};
any '/api/track_location' => sub {
my ( $c ) = @_;
$c->oauth( 'track_location' )
|| return $c->render( status => 401, text => 'You cannot track location' );
$c->render( text => "Target acquired" );
};
get '/' => sub {
my ( $c ) = @_;
$c->render( text => "Welcome to Overly Attached Social Network" );
};
app->start;
# vim: ts=2:sw=2:et