mcso has asked for the wisdom of the Perl Monks concerning the following question:

Hello monks!
I am trying to figure out what I am doing wrong, but I can't seem to find my problem. I am trying to get the hang of the Catalyst framework, and right now I am playing around with authentication. Every time I try to authenticate a login, I get the following message in the Catalyst debug output:
[error] authenticate called with nonexistant realm: 'default'.
In lib/MyApp.pm, authentication is configured as following:
__PACKAGE__->config( 'Plugin::Authentication' => { use_session => 1, default_realm => 'default', default => { credentials => { class => 'Password', password_field => 'Password', password_type => 'hashed', password_hash_type => 'SHA-1' }, store => { class => 'DBIx::Class', user_model => 'MyDB::Users', id_field => 'Username', use_userdata_from_session => 1 } } } );
And my login/authentication code is as follows:
sub base :Chained('/') :PathPart('myapp') :CaptureArgs(0) {} sub unauthenticated :Chained('base') :PathPart('authentication') :Capt +ureArgs(0) {} sub login :Chained('unauthenticated') :PathPart('login') :ActionClass( +'REST') {} sub login_POST { my $this = shift; my $c = shift; my $username = $c->request->data->{'username'} || ''; my $password = $c->request->data->{'password'} || ''; if($username eq '' || $password eq '') { $this->status_bad_request( $c, message => "Invalid username or password" ); $c->dispatch('end'); my $is_authenticated = $c->authenticate( { username => $username, password => $password } ); if(! $is_authenticated) { $this->status_bad_request( $c, message => "Invalid username or password" ); $c->dispatch('end'); } }
Any suggestion of where the error might be would be greatly appreciated.

Replies are listed 'Best First'.
Re: [Catalyst] authenticate called with nonexistant realm: 'default'
by Your Mother (Archbishop) on Apr 14, 2014 at 18:23 UTC

    Are you using an older version of the plugin, Catalyst::Plugin::Authentication?

    Until version 0.10008 of this module, you needed to put all the realms inside a "realms" key in the configuration.

    If so, you can either upgrade or try…

    __PACKAGE__->config( 'Plugin::Authentication' => { use_session => 1, default_realm => 'default', realms => { default => { credentials => { class => 'Password'…
      I am using version 0.10023.
      I have tested with the pre version 0.10008 of the configuration, just to be sure, but no luck.
      I have also tried to put the configuration in the same file as my login function (don't know if that can make any difference?), but it still doesn't seem to find the realm 'default', or any other I might put in.

        I messed around with this a little bit more last night but had exactly the same experience you did. There seems to be something wrong with the docs or a newish bug. I have used the auth package in lots of places without problems before so it's probably something simple that's missing/wrong. I won't have time to look at this today but if no one else chimes in I will try again when I can.

Re: [Catalyst] authenticate called with nonexistant realm: 'default'
by Anonymous Monk on Apr 14, 2014 at 17:48 UTC
    I suggest that to start with you "Google it" ... nonexistent realm. Your core issue is probably not at all Perl-specific.