blib/lib/LWP/Authen/Gooddata.pm untested

filter: Statementstmt 0.0% 0 / 7 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 1 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 15 SCAR 30.0
CC
4
Cov
0%
authenticate
20.0
CRAP 20.0
1 package LWP::Authen::Gooddata;
2  
3 =head1 NAME
4  
5 LWP::Authen::Gooddata - Handle GoodData HTTP authentication mechanism
6  
7 =head1 SYNOPSIS
8  
9 use WWW::GoodData::Agent;
10 my $agent = new WWW::GoodData::Agent ('https://secure.gooddata.com/gdc');
11 $agent->post ('/gdc/account/login', ...);
12 # The authentication cookie gets obtained transparently here
13 $agent->get ('/gdc/md');
14  
15 =head1 DESCRIPTION
16  
17 B<LWP::Authen::Gooddata> gets loaded and invoked by a L<LWP::UserAgent>,
18 or its subclass such as L<WWW::GoodData::Agent>, upon reciept of 401
19 "Unauthorized" response from the server which indicates use of "GoodData"
20 authentization mechanism in the "WWW-Authenticate" header.
21  
22 If the challenge indicates the temporary authentization cookie needs
23 to be refreshed it does so transparently and reissues the request,
24 otherwise dies with appropriate explanation.
25  
26 =head1 METHODS
27  
28 =over 4
29  
30 =item B<authenticate> [PARAMS]
31  
32 Called by LWP::UserAgent internally.
33  
34 =cut
35  
36 sub authenticate
37 {
38 my ($class, $agent, $proxy, $challenge, $response,
39 $request, $arg, $size) = @_;
40  
41 # Not an useful 401 from backend, pass the response
42 return $response unless $challenge->{cookie};
43  
44 # Need to obtain super-secure token
45 die 'Login required' if $challenge->{cookie} eq 'GDCAuthSST';
46  
47 # Everything else should be a token refresh
48 die 'Required authentication not supported by client'
49 if $challenge->{cookie} ne 'GDCAuthTT';
50  
51 # Refresh the token cookie
52 # We should obtain the URI from WWW::GoodData somehow...
53 #die $gdc->get_uri (qw/token/);
54 $agent->get ('/gdc/account/token');
55  
56 $request->header (Cookie => '');
57  
58 # Retry the request
59 return $agent->simple_request ($request);
60 }
61  
62 =back
63  
64 =head1 SEE ALSO
65  
66 =over
67  
68 =item *
69  
70 L<http://developer.gooddata.com/api/auth.html> -- Specification of the GoodData authentization mechanism
71  
72 =item *
73  
74 L<LWP::UserAgent> -- The Perl HTTP agent
75  
76 =back
77  
78 =head1 BUGS
79  
80 GoodData authentization mechanism is not an internet standard and thus
81 puts an interoperability barrier. Unfortunatelly, no standard and widely
82 supported mechanism provides comparable benefits (mostly server-side
83 performance coupled with sanity of implementation). Probably an alternative
84 mechanism should be provided (Basic or Digest, which are both widely
85 available) for the client to negotiate.
86  
87 =head1 COPYRIGHT
88  
89 Copyright 2011, Lubomir Rintel
90  
91 This program is free software; you can redistribute it and/or modify it
92 under the same terms as Perl itself.
93  
94 =head1 AUTHOR
95  
96 Lubomir Rintel C<lkundrak@v3.sk>
97  
98 =cut
99  
100 1;