Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ref #2 more docs regarding JWTs and auto revoke issue
- Loading branch information
Showing
7 changed files
with
123 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#!perl | ||
|
||
use strict; | ||
use warnings; | ||
|
||
use Mojolicious::Lite; | ||
use Test::More; | ||
use FindBin qw/ $Bin /; | ||
use lib $Bin; | ||
use AllTests; | ||
|
||
MOJO_APP: { | ||
# plugin configuration | ||
plugin 'OAuth2::Server' => { | ||
jwt_secret => 'prince edward island potatoes', | ||
clients => { | ||
1 => { | ||
client_secret => 'boo', | ||
scopes => { | ||
eat => 1, | ||
drink => 0, | ||
sleep => 1, | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
group { | ||
# /api - must be authorized | ||
under '/api' => sub { | ||
my ( $c ) = @_; | ||
return 1 if $c->oauth; | ||
$c->render( status => 401, text => 'Unauthorized' ); | ||
return undef; | ||
}; | ||
|
||
get '/eat' => sub { shift->render( text => "food"); }; | ||
}; | ||
|
||
# /sleep - must be authorized and have sleep scope | ||
get '/api/sleep' => sub { | ||
my ( $c ) = @_; | ||
$c->oauth( 'sleep' ) | ||
|| $c->render( status => 401, text => 'You cannot sleep' ); | ||
|
||
$c->render( text => "bed" ); | ||
}; | ||
}; | ||
|
||
AllTests::run({ | ||
skip_revoke_tests => 1, | ||
}); | ||
|
||
done_testing(); | ||
|
||
# vim: ts=2:sw=2:et |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters