http://qs1969.pair.com?node_id=1181123

cLive ;-) has asked for the wisdom of the Perl Monks concerning the following question:

I've broken this down to a minimal case:
package MyApp; use Dancer2; use Dancer2::Plugin::DBIC; use Dancer2::Plugin::Auth::Extensible; our $VERSION = '0.1'; get '/test' => require_login sub { my $user = logged_in_user; return "Hi there, $user->{username}"; }; true;
And here's the config I'm working from:
appname: "MyApp" layout: "main" charset: "UTF-8" template: template_toolkit engines: template: template_toolkit: start_tag: '<%' end_tag: '%>' PLUGIN_BASE: 'Template::Plugin::Pagination' session: DBIC: dsn: dbi:Pg:dbname=my_app schema_class: MyApp::Schema user: starman password: ***** plugins: DBIC: default: dsn: dbi:Pg:dbname=my_app schema_class: MyApp::Schema user: starman password: ***** options: AutoCommit: 1 AutoInactiveDestroy: 1 PrintError: 0 RaiseError: 1 Auth::Extensible: realms: users: provider: 'DBIC' users_resultset: 'User' roles_resultset: 'Role' user_roles_resultset: 'UserRole'

When I navigate to /test, I get the login page.
When I enter an invalid username and password, I get the error "LOGIN FAILED" message.
When I enter a correct username and password, the login page appears to refresh, with the URL changed - each time the return_url query string is prefixed withan extra %25%2F. Eg, after a couple of loads, it looks like this:

/login?return_url=%2F%252F%252Ftest

I guess I have 2 questions - (1) Why isn't it now displaying the /test route, and (2) Is there anyway I can set up my config so I don't have to repeat the DBIC login data.

I've been going round in circles on this all day. It's probably a stupid typo somewhere. Any ideas?

Replies are listed 'Best First'.
Re: Can't get Dancer2 Auth::Extensible with DBIC working
by choroba (Archbishop) on Feb 05, 2017 at 17:34 UTC
    %25%2F corresponds to %/ . Haven't you written %/ instead of %> somewhere, maybe?

    ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,
      I don't think so. For now, I've rolled the auth back and I'm going to rebuild the app from scratch to determine where the issue could be.
Re: Can't get Dancer2 Auth::Extensible with DBIC working
by erix (Prior) on Feb 06, 2017 at 05:15 UTC

    (2) Is there anyway I can set up my config so I don't have to repeat the DBIC login data.

    If the objective is, as I assume, to avoid having the password there (twice): PostgreSQL offers the possibility to set up postgres services, with connection-details in a so-called service-file, leading to e.g. dbi:Pg:service=dev

    It is also possible to setup DBI to connect using just 'dbi:Pg:', with postgres' libpq library picking up connection-info from the environment ( see PGSERVICE in the fine manual; and also: PG environmental variables ).

    (And there is even the DBI_DSN env var to put the 'dbi:Pg:'-part in the environment:

    DBI_DSN=dbi:Pg: perl -MDBI -E 'print DBI->connect, "\n"' DBI::db=HASH(0x181f760)
    )