<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Tue, Oct 13, 2015 at 7:00 AM, <span dir="ltr"><<a href="mailto:dancer-users-request@dancer.pm" target="_blank">dancer-users-request@dancer.pm</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div style="overflow:hidden">I see Dancer2::Plugin::REST, is that the recommended one? It looks good? any<br>Â
experiences with it?</div></blockquote></div><br></div><div class="gmail_extra">My code serves REST without the use of that plugin. It was good, but it did not seem to help me much.<br><br></div><div class="gmail_extra">I have been writing a simple decorator plugin to help with JWT JSON Web Tokens. So my route can look like this:<br> <span style="font-family:monospace,monospace"><br>check_auth ['post', 'put'] => '/cr_user' => sub {<br>   my ($jwt_sub) = @_;<br>   my $dir = _connect_dir();<br><br>   my $role_valid ;<br>   my $ret;<br>   if( $jwt_sub) {<br>       my $admin_user = $dir->get_user({ username => $jwt_sub });</span><br> <br></div><div class="gmail_extra">The plugin has this:<br><span style="font-family:monospace,monospace"><br>use Crypt::JWT qw(encode_jwt decode_jwt);<br>...<br>register 'check_auth' => sub {<br>   my ( $dsl, $pattern, @rest ) = @_;<br><br>   my $default_methods = [ 'get', 'post' ];<br><br>   # If the given pattern is an ArrayRef, we override the defaults<br>   # and pass these onto to DSL->any()<br>   if( ref($pattern) eq "ARRAY" ) {<br>       $default_methods = $pattern;<br>       $pattern = shift(@rest);<br>   }<br>   my $code;<br>   for my $e (@rest) { $code = $e if ( ref($e) eq 'CODE' ) }<br><br>   my $content_type = plugin_setting->{content_type} || 'text/xml';<br><br>   my $authenticated_route = sub {<br>       # Default response content type<br>       $dsl->response->header('</span><span style="font-family:monospace,monospace">Content-Type')<br>         or $dsl->response->content_type( $content_type );<br>       # must be authenticated<br>       # get token from header<br>       my $jwt_sub;<br>       my $token = $dsl->request->header('</span><span style="font-family:monospace,monospace">authorization');<br>       if ( $token) {<br>         # check the JWT of this request<br>         my $secret = plugin_setting->{'jwt_secret'}</span><span style="font-family:monospace,monospace">;<br>         try{<br>           my $data = decode_jwt(token=>$token, key=>$secret);<br></span></div><div class="gmail_extra"><br>Much of this is copied from Dancer2::Plugin::Auth::Tiny by D.A. Golden. Now I should try Yanick's Plugin2.<br><br></div><div dir="ltr">Cheers -- Rick<br><br></div><div class="gmail_extra">
</div></div>