Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

Journal of LTjake (4001)

Thursday April 20, 2006
12:34 PM

Addendum to TypeKey-Catalyst integration

[ #29390 ]

Since my initial tutorial on integrating TypeKey authentication with local a Catalyst database user, there have been a few significant changes that greatly simplify the process.

The new method requires the latest Catalyst::Plugin::Authentication::Store::DBIC from the svn repository. (Note: A new version of this plugin will soon to be released to CPAN. Watch this space.)

  1. Credential/Store config

    The configuration is much the same as before, except for two options: auto_create_user and auto_update_user

        server           :
        key_url          :
        version          : 1
        auth_store       : default
        user_class      : Accounts::Account
        user_field      : username
        auto_create_user: 1
        auto_update_user: 1
        role_class          : Accounts::Role
        role_field          : name
        role_rel            : account_roles
        user_role_user_field: account

    Those two options will drive the functionality that we emulated in the old "AutoCreate" plugin.

  2. User Class Modification

    The plugin will call auto_create and auto_update on your account class when those events happen.

    For auto_create to work, it needs to be called on a ResultSet, so you should use the ResultSetManager in your user class. Each sub gets a number of parameters, the last one being the results of the typekey authentication (a hashref with name, nick, email and ts keys). Use that hashref to add or update the user.

    NB: it's possible for auto_update to get called in situations where it hasn't authenticated, so it's important to get out of the process if the data doesn't exist.

    package MyApp::Schema::Account;

    use strict;
    use warnings;

    use base qw( DBIx::Class );

    __PACKAGE__->load_components( qw( PK::Auto ResultSetManager Core ) );

    # ...

    sub auto_create : ResultSet {
        my( $self, $username, $req, $res ) = @_;
        $self->create( {
            # Deal with $res here
        } );

    sub auto_update {
        my( $self, $username, $req, $res ) = @_;
        return unless $res;

        # Deal with $res here



That's it! A much tighter process, don't you think?

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.