2008-02-06
Limilic を Basic 認証にしてみる
フロントで Basic 認証かけておいて、適当な openid url をでっち上げる例。
openid 的な url を作るために、$c->config->{namespace} に http://profile.vaginarepos.org/ とか適当な値を入れておく。それにユーザ名を足したものを openid として使う。
Index: lib/Cpip.pm =================================================================== --- lib/Cpip.pm (revision 6256) +++ lib/Cpip.pm (working copy) @@ -80,14 +81,14 @@ } } -sub auto : Private { - my ( $self, $c ) = @_; - if ( $c->session && $c->session->{user} ) { - my $user = $c->model('DBIC::Users')->find( { id => $c->session->{user} } ); - $c->req->{user} = $user if $user; - } - 1; -} +# sub auto : Private { +# my ( $self, $c ) = @_; +# if ( $c->session && $c->session->{user} ) { +# my $user = $c->model('DBIC::Users')->find( { id => $c->session->{user} } ); +# $c->req->{user} = $user if $user; +# } +# 1; +# } 1; Index: lib/Cpip/Controller/Root.pm =================================================================== --- lib/Cpip/Controller/Root.pm (revision 6256) +++ lib/Cpip/Controller/Root.pm (working copy) @@ -77,8 +77,51 @@ $c->response->body($feed->as_xml); } +sub auto : Private { + my ( $self, $c ) = @_; + + if ( $c->session && $c->session->{user} ) { + my $user = $c->model('DBIC::Users')->find( { id => $c->session->{user} } ); + $c->req->{user} = $user if $user; + return 1; + } + + # + # all access is granted by frontend proxy + # + my ($username, $pass) = $c->req->headers->authorization_basic; + + my $url = $c->config->{namespace} . $username . '/'; + my $identity = { + atom => undef, + foaf => undef, + foafmaker => undef, + rss => undef, + signed_fields => { + identity => $url, + mode => 'id_res', + }, + identity => $url, + }; + + my $user = $c->model('DBIC::Users')->update_or_create({ + openid => $identity->{identity}, + identity => $identity, + }, { + key => 'openid', + }); + + $c->req->{openid_identity} = $identity; + $c->req->{user} = $user; + $c->session->{user} = $c->req->{user}->id; + + return 1; +} + sub login : Local { my ( $self, $c ) = @_; + return $c->res->redirect('/'); + $c->authenticate_openid; my $n = $c->req->param('n') || '/'; $c->res->redirect($n) unless $c->res->redirect;
トラックバック - http://d.hatena.ne.jp/woremacx/20080206/1202223880
