1 package TestApp::Controller::Root;
5 no warnings "uninitialized";
6 use base 'Catalyst::Controller';
7 use Net::OpenID::Server;
9 __PACKAGE__->config->{namespace} = '';
13 TestApp::Controller::Root - Root Controller for TestApp
22 sub provider : Local {
23 my ( $self, $c, $username ) = @_;
25 my $nos = Net::OpenID::Server
27 get_args => $c->req->query_params,
28 post_args => $c->req->body_params,
29 get_user => sub { $c->user },
31 my ( $user, $identity_url ) = @_;
33 my ( $check ) = $identity_url =~ /(\w+)\z/;
34 return $check eq $user->id; # simple auth here
37 my ( $user, $trust_root, $is_identity ) = @_;
38 return $is_identity; # enough that they passed is_identity
40 setup_url => $c->uri_for($c->req->path, {moo => "setup"}),
41 server_secret => $c->config->{startup_time},
44 # From your OpenID server endpoint:
46 my ( $type, $data ) = $nos->handle_page;
48 if ($type eq "redirect")
50 $c->res->redirect($data);
52 elsif ($type eq "setup")
54 my %setup_opts = %{$data};
56 You're not signed in so you can't be verified.
57 <a href="/login">Sign in</a> | <a href="/signin_openid">OpenId</a>.
59 # it's then your job to redirect them at the end to "return_to"
60 # (or whatever you've named it in setup_map)
64 $c->res->content_type($type);
67 my $server_uri = $c->uri_for($c->req->path);
68 $data =~ s,(?=</head>),<link rel="openid.server" href="$server_uri" />,;
76 $c->logout if $c->user_exists;
78 $c->res->redirect($c->uri_for("/"));
84 if ( $c->req->method eq 'POST'
86 $c->authenticate({ username => $c->req->body_params->{username},
87 password => $c->req->body_params->{password} }) )
89 # $c->res->body("You are signed in!");
90 $c->res->redirect($c->uri_for("/"));
94 my $action = $c->req->uri->path;
96 <html><head/><body><form name="login" action="$action" method="POST">
97 <input type="text" name="username" />
98 <input type="password" name="password" />
99 <input type="submit" value="Sign in" />
107 sub signin_openid : Local {
110 if ( $c->authenticate({}, "openid") )
112 $c->res->body("You did it with OpenID!");
116 my $action = $c->req->uri->path;
118 <form action="$action" method="GET" name="openid">
119 <input type="text" name="openid_identifier" class="openid" size="50" />
120 <input type="submit" value="Sign in with OpenID" />
126 sub default : Private {
127 my ( $self, $c ) = @_;
131 $c->user ? "" : "not",
133 $c->user ? ( $c->user->id || %{$c->user} ) : '<a href="/login">Sign in</a> | <a href="/signin_openid">OpenId</a>.'
139 my ( $self, $c ) = @_;
140 $c->response->content_type("text/html");
145 This library is free software, you can redistribute it and/or modify
146 it under the same terms as Perl itself.