File Coverage

blib/lib/Catalyst/Plugin/Session/State/Auth.pm
Criterion Covered Total %
statement 1 3 33.3
branch n/a
condition n/a
subroutine 1 1 100.0
pod n/a
total 2 4 50.0


line stmt bran cond sub pod time code
1             package Catalyst::Plugin::Session::State::Auth;
2 1     1   1630 use Moose;
  0            
  0            
3             use MRO::Compat;
4             use HTTP::Headers::Util qw(split_header_words);
5              
6             use namespace::clean -except => 'meta';
7              
8             our $VERSION = '0.0005';
9              
10             extends 'Catalyst::Plugin::Session::State';
11             with 'MooseX::Emulate::Class::Accessor::Fast';
12              
13             __PACKAGE__->mk_accessors(qw/_sessionid_from_auth_signature/);
14              
15             sub get_session_id {
16             my ( $c, @args ) = @_;
17             return $c->_sessionid_from_auth_signature || $c->maybe::next::method(@args);
18             }
19              
20             sub delete_session_id {
21             my ( $c, @args ) = @_;
22             $c->_sessionid_from_auth_signature(undef);
23             $c->maybe::next::method(@args);
24             }
25              
26             sub finalize {
27             my $c = shift;
28             return $c->maybe::next::method(@_);
29             }
30              
31             sub prepare_path {
32             my $c = shift;
33              
34             $c->maybe::next::method(@_);
35              
36             if ( $c->request->header('authorization') ){
37             my @values = split_header_words( $c->request->header('authorization') );
38             my $signature = $values[-1][-1];
39             $c->_sessionid_from_auth_signature($signature);
40             $c->_tried_loading_session_id(0);
41             $c->log->debug(qq/Found sessionid "$signature" in MAC authentication/)
42             if $c->debug;
43             }
44             }
45              
46             __PACKAGE__
47              
48             __END__
49              
50             1;
51              
52             =head1 NAME
53              
54             Catalyst::Plugin::Session::State::Auth -
55             Use signature in HTTP MAC authentication scheme to pass the session id between requests
56              
57             =head1 SYNOPSIS
58             In MyApp.pm
59             use Catalyst qw/
60             Session
61             Session::State::Auth
62             Session::Store::Foo
63             /;
64              
65             =head1 DESCRIPTION
66              
67             In your HTTP request
68             Authorization: MAC token="h480djs93hd8",
69             timestamp="137131200",
70             nonce="dj83hs9s",
71             signature="kDZvddkndxvhGRXZhvuDjEWhGeE="
72              
73             In order for L<Catalyst::Plugin::Session> to work,
74             Use the mac signature to pass your sessionid,
75             and the session data needs to be stored on the server.
76              
77             Note that this pre-alpha version has no way to rewrite outgoing data.
78              
79             =head1 METHODS
80              
81             =head1 BUGS
82              
83             =head1 SEE ALSO
84              
85             L<Catalyst>, L<Catalyst::Plugin::Session>,L<Catalyst::Plugin::Session::State::URI>.
86              
87             =head1 AUTHOR
88              
89             Warachet Samtalee (zdk)
90              
91             This module is derived from L<Catalyst::Plugin::Session::State::URI> code.
92              
93             =head1 COPYRIGHT & LICENSE
94              
95             Copyright 2011 the above author(s).
96              
97             This sofware is free software, and is licensed under the same terms as perl itself.
98              
99             =cut