Changeset 135

Show
Ignore:
Timestamp:
06/02/06 14:41:22 (2 years ago)
Author:
miya
Message:

commit.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • library/perl/trunk/Catalyst-Plugin-Authentication-Credential-JugemKey/lib/Catalyst/Plugin/Authentication/Credential/JugemKey.pm

    r134 r135  
    33use warnings; 
    44use strict; 
     5 
     6our $VERSION = '0.01'; 
     7 
     8use WebService::JugemKey::Auth; 
     9use UNIVERSAL::require; 
     10use NEXT; 
     11 
     12sub setup { 
     13    my $c = shift; 
     14 
     15    my $config = $c->config->{authentication}->{jugemkey} ||= {}; 
     16 
     17    $config->{jugemkey_object} ||= do { 
     18        ( $config->{user_class} 
     19              ||= 'Catalyst::Plugin::Authentication::User::Hash' )->require; 
     20 
     21        WebService::JugemKey::Auth->new( 
     22            {   api_key => $config->{api_key}, 
     23                secret  => $config->{secret}, 
     24            } 
     25        ); 
     26    }; 
     27 
     28    $c->NEXT::setup(@_); 
     29} 
     30 
     31sub authenticate_jugemkey_url { 
     32    my ($c, $params) = @_; 
     33    warn $params; 
     34    $c->config->{authentication}->{jugemkey}->{jugemkey_object}->uri_to_login($params); 
     35} 
     36 
     37sub authenticate_jugemkey_get_token { 
     38    my $c = shift; 
     39 
     40    my $config = $c->config->{authentication}->{jugemkey}; 
     41    my $jugemkey = $config->{jugemkery_object}; 
     42 
     43    my $frob = $c->req->params->{frob} or return; 
     44 
     45    if ( my $user = $jugemkey->get_token($frob) ) { 
     46        $c->log->debug("Successfully get token of user '$user->name'.") 
     47            if $c->debug; 
     48 
     49        my $store = $config->{store} || $c->default_auth_store; 
     50        if ( $store 
     51            and my $store_user = $store->get_user( $user->name, $user ) ) 
     52        { 
     53            $c->set_authenticated($store_user); 
     54        } 
     55        else { 
     56            $user = $config->{user_class}->new($user); 
     57            $c->set_authenticated($user); 
     58        } 
     59 
     60        return 1; 
     61    } 
     62    else { 
     63        $c->log->debug( 
     64            sprintf "Failed to authenticate hatena.  Reason: '%s'", 
     65            $jugemkey->errstr, ) 
     66            if $c->debug; 
     67 
     68        return; 
     69    } 
     70} 
     71 
    572 
    673=head1 NAME 
     
    1380 
    1481=cut 
    15  
    16 our $VERSION = '0.01'; 
    1782 
    1883=head1 SYNOPSIS