[Catalyst-commits] r6462 - in trunk/examples/OpenID:
Consumer/lib/Consumer/Controller Server/lib/Catalyst/Action/OpenID
Server/lib/Catalyst/Controller Server/lib/OpenID/Controller
Server/root/server
edenc at dev.catalyst.perl.org
edenc at dev.catalyst.perl.org
Tue Jun 12 00:37:51 GMT 2007
Author: edenc
Date: 2007-06-12 00:37:50 +0100 (Tue, 12 Jun 2007)
New Revision: 6462
Modified:
trunk/examples/OpenID/Consumer/lib/Consumer/Controller/Root.pm
trunk/examples/OpenID/Server/lib/Catalyst/Action/OpenID/Identity.pm
trunk/examples/OpenID/Server/lib/Catalyst/Action/OpenID/Server.pm
trunk/examples/OpenID/Server/lib/Catalyst/Controller/OpenID.pm
trunk/examples/OpenID/Server/lib/OpenID/Controller/Server.pm
trunk/examples/OpenID/Server/root/server/server.tt
Log:
added trust setup
Modified: trunk/examples/OpenID/Consumer/lib/Consumer/Controller/Root.pm
===================================================================
--- trunk/examples/OpenID/Consumer/lib/Consumer/Controller/Root.pm 2007-06-08 17:41:52 UTC (rev 6461)
+++ trunk/examples/OpenID/Consumer/lib/Consumer/Controller/Root.pm 2007-06-11 23:37:50 UTC (rev 6462)
@@ -33,13 +33,8 @@
}
}
-use Data::Dump;
+sub index : Local {}
-sub index : Local {
- my ( $self, $c ) = @_;
- $c->log->debug( Data::Dump::dump( $c->user ) ) if $c->user_exists;
-}
-
=head2 end
Attempt to render a view, if needed.
Modified: trunk/examples/OpenID/Server/lib/Catalyst/Action/OpenID/Identity.pm
===================================================================
--- trunk/examples/OpenID/Server/lib/Catalyst/Action/OpenID/Identity.pm 2007-06-08 17:41:52 UTC (rev 6461)
+++ trunk/examples/OpenID/Server/lib/Catalyst/Action/OpenID/Identity.pm 2007-06-11 23:37:50 UTC (rev 6462)
@@ -28,13 +28,8 @@
return;
}
-
- my $server = $self->attributes->{ServerAction}[0];
- # this has to be resolved on each call since we don't
- # know the load order for actions
- my $action = $controller->action_for($server);
-
+ my $action = $controller->_server_action;
my $openid_var = $self->attributes->{OPENID_VAR} || 'openid_server';
my $href = $c->uri_for($action)->as_string;
@@ -61,13 +56,12 @@
=head1 SEE ALSO
-L<Catalyst::Controller::OpenID> L<Catalyst::Action::OpenID::Server>
+L<Catalyst::Controller::OpenID>, L<Catalyst::Action::OpenID::Server>
=head1 AUTHOR
-Eden Cardoso Cardim C<< <edencardim at gmail.com> >>
+Eden C. Cardim C<< <edencardim at gmail.com> >>
-
=head1 LICENSE
This library is copyright (C) 2007, PictureTrail.com
Modified: trunk/examples/OpenID/Server/lib/Catalyst/Action/OpenID/Server.pm
===================================================================
--- trunk/examples/OpenID/Server/lib/Catalyst/Action/OpenID/Server.pm 2007-06-08 17:41:52 UTC (rev 6461)
+++ trunk/examples/OpenID/Server/lib/Catalyst/Action/OpenID/Server.pm 2007-06-11 23:37:50 UTC (rev 6462)
@@ -2,8 +2,6 @@
use warnings;
use strict;
-use Carp;
-use Smart::Comments;
our $VERSION = '0.01';
@@ -13,15 +11,21 @@
sub new {
my $self = shift->NEXT::new(@_);
- $self->attributes->{Args}[0] = 0;
+ if ( !( exists $self->attributes->{Args} ) ) {
+ $self->attributes->{Args}[0] = 0;
+ }
return $self;
}
+sub openid_register {
+ my ( $self, $controller ) = @_;
+ $controller->_server_action($self);
+}
+
sub execute {
my $self = shift;
my ( $controller, $c ) = @_;
- $self->NEXT::execute(@_);
-
+
my $nos = Net::OpenID::Server->new(
get_args => $c->req->query_parameters,
post_args => $c->req->body_parameters,
@@ -37,7 +41,11 @@
my $base = $c->req->base;
( my $identity_action = $identity ) =~ s/^$base//;
- $c->log->debug('checking identity for ' . $user->id);
+
+ if ( $c->debug ) {
+ $c->log->debug( 'checking identity for ' . $user->id );
+ }
+
$c->forward("/$identity_action");
return $c->stash->{is_identity};
},
@@ -46,8 +54,9 @@
is_trusted => sub {
my ( $user, $trust_root, $is_identity ) = @_;
- #TODO check trusts in session
- return 1;
+ return unless defined $user;
+ return unless $is_identity;
+ return $self->is_trusted( $controller, $c, $trust_root );
},
# generate our half of the server secret
@@ -61,18 +70,69 @@
$c->res->redirect($data);
}
elsif ( $type eq 'setup' ) {
-
- # if we get here, authentication or trust has failed in NEXT::execute
- # try again indefinately...
- return;
+ $self->NEXT::execute(@_);
+ $self->handle_trust( @_, $nos, $data ) if $c->user_exists;
}
else {
+ if ( $c->debug ) {
+ $c->log->debug("[OpenID] setting type: $type");
+ $c->log->debug("[OpenID] setting body: $data");
+ }
+
$c->res->content_type($type);
- $c->log->debug("Setting body: $data");
$c->res->body($data);
}
}
+sub is_trusted {
+ my $self = shift;
+ my ( $controller, $c, $trust_root ) = @_;
+
+ my $stash = $c->stash;
+ my $session = $c->session;
+ my $trusted = $session->{openid}{trusted};
+ my $untrusted = $session->{openid}{untrusted};
+
+ $c->log->debug(join ', ', keys %{$session->{openid}});
+ if ( exists $trusted->{$trust_root} ) {
+ $stash->{trust_consumer} = 1;
+ }
+ elsif ( exists $untrusted->{$trust_root} ) {
+ $stash->{trust_consumer} = 0;
+ }
+
+ # user hasn't been given a chance to aprove the consumer url yet
+ else {
+ $stash->{consumer_url} = $trust_root;
+ }
+
+ return $stash->{trust_consumer};
+}
+
+sub handle_trust {
+ my $self = shift;
+ my ( $controller, $c, $nos, $data ) = @_;
+
+ my $stash = $c->stash;
+ my $session = $c->session;
+ my $trust_root = $data->{trust_root};
+
+ # store trust for this url
+ if ( exists $stash->{trust_consumer} ) {
+ if ( $stash->{trust_consumer} ) {
+ $session->{openid}{trusted}{$trust_root} = 1;
+ $c->res->redirect( $nos->signed_return_url(%$data) );
+ }
+ else {
+ $session->{openid}{untrusted}{$trust_root} = 1;
+ $c->res->redirect(
+ $nos->cancel_return_url( return_to => $data->{return_to} ) );
+ }
+ return;
+ }
+ return 1;
+}
+
1; # Magic true value required at end of module
__END__
@@ -96,7 +156,7 @@
=head1 AUTHOR
-Eden Cardoso Cardim C<< <edencardim at gmail.com> >>
+Eden C. Cardim C<< <edencardim at gmail.com> >>
=head1 LICENSE
Modified: trunk/examples/OpenID/Server/lib/Catalyst/Controller/OpenID.pm
===================================================================
--- trunk/examples/OpenID/Server/lib/Catalyst/Controller/OpenID.pm 2007-06-08 17:41:52 UTC (rev 6461)
+++ trunk/examples/OpenID/Server/lib/Catalyst/Controller/OpenID.pm 2007-06-11 23:37:50 UTC (rev 6462)
@@ -3,13 +3,22 @@
use warnings;
use strict;
+use base 'Catalyst::Controller';
+
our $VERSION = '0.01';
-# Module implementation here
+__PACKAGE__->mk_accessors(qw/_server_action/);
-# this will register Server and Identity actions shortly
+sub create_action {
+ my $self = shift;
+ my $action = $self->NEXT::create_action(@_);
+ if ( my $register = $action->can('openid_register') ) {
+ $register->($action, $self);
+ }
+ return $action;
+}
-1; # Magic true value required at end of module
+1; # Magic true value required at end of module
__END__
=head1 NAME
Modified: trunk/examples/OpenID/Server/lib/OpenID/Controller/Server.pm
===================================================================
--- trunk/examples/OpenID/Server/lib/OpenID/Controller/Server.pm 2007-06-08 17:41:52 UTC (rev 6461)
+++ trunk/examples/OpenID/Server/lib/OpenID/Controller/Server.pm 2007-06-11 23:37:50 UTC (rev 6462)
@@ -3,18 +3,26 @@
use strict;
use warnings;
-use base 'Catalyst::Controller';
+use base 'Catalyst::Controller::OpenID';
-use Net::OpenID::Server;
-
-sub identity : Local ActionClass('OpenID::Identity')
- ServerAction('server') {
+sub identity : Local ActionClass('OpenID::Identity') {
}
sub server : Local ActionClass('OpenID::Server') {
my ( $self, $c ) = @_;
- if ( my $user = $c->req->param("user")
- and my $password = $c->req->param("password") )
+
+ my $params = $c->req->params;
+ if ( $c->user_exists ) {
+ $c->log->debug('user_exists');
+ if ( exists $params->{trust_consumer} ) {
+ $c->log->debug( 'trust_consumer: ' . $params->{trust_consumer} );
+ $c->log->debug( 'trust_consumer: ' . ( $params->{trust_consumer} eq 'yes' ) );
+ $c->stash->{trust_consumer}
+ = ( $params->{trust_consumer} eq 'yes' );
+ }
+ }
+ elsif ( my $user = $params->{user}
+ and my $password = $params->{password} )
{
if ( !$c->login( $user, $password ) ) {
$c->stash->{bad_login} = 1;
Modified: trunk/examples/OpenID/Server/root/server/server.tt
===================================================================
--- trunk/examples/OpenID/Server/root/server/server.tt 2007-06-08 17:41:52 UTC (rev 6461)
+++ trunk/examples/OpenID/Server/root/server/server.tt 2007-06-11 23:37:50 UTC (rev 6462)
@@ -1,7 +1,14 @@
[%
IF bad_login; '<p>wrong username or password</p>'; END;
+IF c.param('user') && c.param('password') && !is_identity; "<p>you don't own this identity</p>"; END;
%]<form action="[% c.uri_for(c.action, c.req.query_parameters).as_string %]" method="POST">
+[% IF !c.user_exists %]
<p><input type="text" name="user" class="openid" /></p>
<p><input type="password" name="password" class="openid" /></p>
+[% ELSE %]
+ <p>Would you like to share your identity with [% consumer_url %]?
+ yes <input type="radio" name="trust_consumer" value="yes"/>
+ no <input type="radio" name="trust_consumer" value="no"/></p>
+[% END %]
<p><input type="submit" value="Sign in" /></p>
</form>
More information about the Catalyst-commits
mailing list