{"id":28614201,"url":"https://github.com/perldancer/dancer-plugin-auth-tiny","last_synced_at":"2026-03-10T02:04:12.124Z","repository":{"id":6009890,"uuid":"7233138","full_name":"PerlDancer/dancer-plugin-auth-tiny","owner":"PerlDancer","description":"Require logged-in user for some routes","archived":false,"fork":false,"pushed_at":"2013-02-27T16:58:14.000Z","size":131,"stargazers_count":2,"open_issues_count":1,"forks_count":1,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-12-13T06:28:20.008Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://metacpan.org/author/DAGOLDEN","language":"Perl","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/PerlDancer.png","metadata":{"files":{"readme":"README.pod","changelog":"Changes","contributing":"CONTRIBUTING","funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-12-19T01:17:06.000Z","updated_at":"2015-10-12T22:16:28.000Z","dependencies_parsed_at":"2022-09-12T09:51:46.225Z","dependency_job_id":null,"html_url":"https://github.com/PerlDancer/dancer-plugin-auth-tiny","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/PerlDancer/dancer-plugin-auth-tiny","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PerlDancer%2Fdancer-plugin-auth-tiny","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PerlDancer%2Fdancer-plugin-auth-tiny/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PerlDancer%2Fdancer-plugin-auth-tiny/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PerlDancer%2Fdancer-plugin-auth-tiny/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/PerlDancer","download_url":"https://codeload.github.com/PerlDancer/dancer-plugin-auth-tiny/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PerlDancer%2Fdancer-plugin-auth-tiny/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30322638,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-10T01:36:58.598Z","status":"online","status_checked_at":"2026-03-10T02:00:06.579Z","response_time":106,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-06-12T01:13:23.815Z","updated_at":"2026-03-10T02:04:09.245Z","avatar_url":"https://github.com/PerlDancer.png","language":"Perl","funding_links":[],"categories":[],"sub_categories":[],"readme":"=pod\n\n=head1 NAME\n\nDancer::Plugin::Auth::Tiny - Require logged-in user for specified routes\n\n=head1 VERSION\n\nversion 0.003\n\n=head1 SYNOPSIS\n\n  use Dancer::Plugin::Auth::Tiny;\n\n  get '/private' =\u003e needs login =\u003e sub { ... };\n\n  get '/login' =\u003e sub {\n    # put 'return_url' in a hidden form field\n    template 'login' =\u003e { return_url =\u003e params-\u003e{return_url} };\n  };\n\n  post '/login' =\u003e sub {\n    if ( _is_valid( params-\u003e{user}, params-\u003e{password} ) ) {\n      session user =\u003e params-\u003e{user},\n      return redirect params-\u003e{return_url} || '/';\n    }\n    else {\n      template 'login' =\u003e { error =\u003e \"invalid username or password\" };\n    }\n  };\n\n  sub _is_valid { ... } # this is up to you\n\n=head1 DESCRIPTION\n\nThis L\u003cDancer\u003e plugin provides an extremely simple way of requiring that a user\nbe logged in before allowing access to certain routes.\n\nIt is not \"Tiny\" in the usual CPAN sense, but it is \"Tiny\" with respect to\nDancer authentication plugins.  It provides very simple sugar to wrap route\nhandlers with an authentication closure.\n\nThe plugin provides the C\u003cneeds\u003e keyword and a default C\u003clogin\u003e wrapper that\nyou can use like this:\n\n  get '/private' =\u003e needs login =\u003e $coderef;\n\nThe code above is roughly equivalent to this:\n\n  get '/private' =\u003e sub {\n    if ( session 'user' ) {\n      goto $coderef;\n    }\n    else {\n      return redirect uri_for( '/login',\n        { return_url =\u003e uri_for( request-\u003epath, request-\u003eparams ) } );\n    }\n  };\n\nIt is up to you to provide the '/login' route, handle actual authentication,\nand set C\u003cuser\u003e session variable if login is successful.\n\nIf the original request contains a parameter in the C\u003cpassthrough\u003e list, it\nwill be added to the login query. For example,\nC\u003chttp://example.com/private?user=dagolden\u003e will be redirected as\nC\u003chttp://example.com/login?user=dagolden\u0026return_url=...\u003e.  This facilitates\npre-populating a login form.\n\n=for Pod::Coverage extend\n\n=head1 CONFIGURATION\n\nYou may override any of these settings:\n\n=over 4\n\n=item *\n\nC\u003clogin_route: /login\u003e -- defines where a protected route is redirected\n\n=item *\n\nC\u003clogged_in_key: user\u003e -- defines the session key that must be true to indicate a logged-in user\n\n=item *\n\nC\u003ccallback_key: return_url\u003e -- defines the parameter key with the original request URL that is passed to the login route\n\n=item *\n\nC\u003cpassthrough: - user\u003e -- a list of parameters that should be passed through to the login handler\n\n=back\n\n=head1 EXTENDING\n\nThe class method C\u003cextend\u003e may be used to add (or override) authentication\ncriteria. For example, to add a check for the C\u003csession 'is_admin'\u003e key:\n\n  Dancer::Plugin::Auth::Tiny-\u003eextend(\n    admin =\u003e sub {\n      my ($coderef) = @_;\n      return sub {\n        if ( session \"is_admin\" ) {\n          goto $coderef;\n        }\n        else {\n          redirect '/access_denied';\n        }\n      };\n    }\n  );\n\n  get '/super_secret' =\u003e needs admin =\u003e sub { ... };\n\nIt takes key/value pairs where the value must be a closure generator that wraps\narguments passed to C\u003cneeds\u003e.\n\nYou could pass additional arguments before the code reference like so:\n\n  # don't conflict with Dancer's any()\n  use Syntax::Keyword::Junction 'any' =\u003e { -as =\u003e 'any_of' };\n\n  Dancer::Plugin::Auth::Tiny-\u003eextend(\n    any_role =\u003e sub {\n      my $coderef = pop;\n      my @requested_roles = @_;\n      return sub {\n        my @user_roles = @{ session(\"roles\") || [] };\n        if ( any_of(@requested_roles) eq any_of(@user_roles) ) {\n          goto $coderef;\n        }\n        else {\n          redirect '/access_denied';\n        }\n      };\n    }\n  );\n\n  get '/parental' =\u003e needs any_role =\u003e qw/mom dad/ =\u003e sub { ... };\n\n=head1 SEE ALSO\n\nFor more complex L\u003cDancer\u003e authentication, see:\n\n=over 4\n\n=item *\n\nL\u003cDancer::Plugin::Auth::Extensible\u003e\n\n=item *\n\nL\u003cDancer::Plugin::Auth::RBAC\u003e\n\n=back\n\nFor password authentication algorithms for your own '/login' handler, see:\n\n=over 4\n\n=item *\n\nL\u003cAuth::Passphrase\u003e\n\n=item *\n\nL\u003cDancer::Plugin::Passphrase\u003e\n\n=back\n\n=head1 ACKNOWLEDGMENTS\n\nThis simplified Auth module was inspired by Dancer::Plugin::Auth::Extensible by\nDavid Precious and discussions about its API by member of the Dancer Users\nmailing list.\n\n=for :stopwords cpan testmatrix url annocpan anno bugtracker rt cpants kwalitee diff irc mailto metadata placeholders metacpan\n\n=head1 SUPPORT\n\n=head2 Bugs / Feature Requests\n\nPlease report any bugs or feature requests through the issue tracker\nat L\u003chttps://github.com/dagolden/dancer-plugin-auth-tiny/issues\u003e.\nYou will be notified automatically of any progress on your issue.\n\n=head2 Source Code\n\nThis is open source software.  The code repository is available for\npublic review and contribution under the terms of the license.\n\nL\u003chttps://github.com/dagolden/dancer-plugin-auth-tiny\u003e\n\n  git clone git://github.com/dagolden/dancer-plugin-auth-tiny.git\n\n=head1 AUTHOR\n\nDavid Golden \u003cdagolden@cpan.org\u003e\n\n=head1 COPYRIGHT AND LICENSE\n\nThis software is Copyright (c) 2012 by David Golden.\n\nThis is free software, licensed under:\n\n  The Apache License, Version 2.0, January 2004\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fperldancer%2Fdancer-plugin-auth-tiny","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fperldancer%2Fdancer-plugin-auth-tiny","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fperldancer%2Fdancer-plugin-auth-tiny/lists"}