Catalyst: How to authenticate against OpenID and get roles from local DBIC
First you need to follow the Catalyst tutorial and enable the authentication and session layers. After that you need to install these two CPAN modules: # cpan install Catalyst::Authentication::Credential::OpenID # cpan install Catalyst::Authentication::Store::DBIx::Class,
After that you need to add the following to myapp.yml. authentication: default_realm: openid realms: openid: credential: class: OpenID dbic: credential: class: Password password_type: none store: class: DBIx::Class user_class: MyAppDB::User id_field: id role_column: user_role And after that you need to add the following code to lib/MyApp/Controller/Root.pm. sub login : Local { my ( $self, $c ) = @_; # eval necessary because LWPx::ParanoidAgent # croaks if invalid URL is specified eval { # Authenticate against OpenID to get user URL if ( $c->authenticate({}, 'openid' ) ) { $c->flash->{'status_msg'}='OpenID login was successful.'; # Create basic user entry unless already found # (or use auto_create_user: 1) unless ( $c->model('MyAppDB::User')->find($c->user->url) ) { $c->model('MyAppDB::User')->create( { id => $c->user->url } ); } # Re-authenticate against local DBIC store if ( $c->authenticate({ id => $c->user->url }, 'dbic') ) { $c->flash->{'status_msg'}='Login was successful.'; $c->response->redirect( $c->uri_for("/") ); } else { $c->flash->{'error_msg'}='Local login failed.'; $c->stash->{'template'}='login.tt'; } } else { $c->stash->{'template'}='login.tt'; } }; if ($@) { $c->log->error("Failure during login: " . $@); $c->flash->{'error_msg'}='Failure during login: ' . $@; $c->stash->{'template'}='login.tt'; } } And finally you create a form to use this method (root/login.tt): <form action="[% c.uri_for('/login') %]" method="get"> <input type="text" name="openid_identifier" value="http://" /> <button type="submit">Sign in with OpenID</button> </form>