This file is indexed.

/usr/share/perl5/Net/Google/AuthSub.pm is in libnet-google-authsub-perl 0.5-2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
package Net::Google::AuthSub;

use strict;
use vars qw($VERSION $APP_NAME);
use LWP::UserAgent;
use HTTP::Request::Common;
use Net::Google::AuthSub::Response;
use URI;

$VERSION  = '0.5';
$APP_NAME = __PACKAGE__."-".$VERSION;

use constant CLIENT_LOGIN => 0;
use constant AUTH_SUB     => 1;

=head1 NAME

Net::Google::AuthSub - interact with sites that implement Google style AuthSub

=head1 SYNOPSIS


    my $auth = Net::Google::AuthSub->new;
    my $response = $auth->login($user, $pass);

    if ($response->is_success) {
        print "Hurrah! Logged in\n";
    } else {
        die "Login failed: ".$response->error."\n";
    }

    my %params = $auth->auth_params;
    $params{Content_Type}             = 'application/atom+xml; charset=UTF-8';
    $params{Content}                  = $xml;
    $params{'X-HTTP-Method-Override'} = 'DELETE';        

    my $request = POST $url, %params;
    my $r = $user_agent->request( $request );


=head1 ABOUT AUTHSUB

AuthSub is Google's method of authentication for their web 
services. It is also used by other web sites.

You can read more about it here.

    http://code.google.com/apis/accounts/Authentication.html

A Google Group for AuthSub is here.

    http://groups.google.com/group/Google-Accounts-API

=head1 DEALING WITH CAPTCHAS

If a login response fails then it may set the error code to
'CaptchRequired' and the response object will allow you to 
retrieve the C<captchatoken> and C<captchaurl> fields.

The C<captchaurl> will be the url to a captcha image or you 
can show the user the web page

    https://www.google.com/accounts/DisplayUnlockCaptcha

Then retry the login attempt passing in the parameters 
C<logintoken> (which is the value of C<captchatoken>) and 
C<logincaptcha> which is the user's answer to the CAPTCHA.


    my $auth = Net::Google::AuthSub->new;
    my $res  = $auth->login($user, $pass);

    if (!$res->is_success && $res->error eq 'CaptchaRequired') {
        my $answer = display_captcha($res->captchaurl);
        $auth->login($user, $pass, logintoken => $res->captchatoken, logincaptcha => $answer);
    }


You can read more here

    http://code.google.com/apis/accounts/AuthForInstalledApps.html#Using

=head1 METHODS

=cut

=head2 new [param[s]]

Return a new authorisation object. The options are

=over 4

=item url

The base url of the web service to authenticate against.

Defaults to C<https://google.com/account>

=item service

Name of the Google service for which authorization is requested such as 'cl' for Calendar.

Defaults to 'xapi' for calendar.

=item source

Short string identifying your application, for logging purposes.

Defaults to 'Net::Google::AuthSub-<VERSION>'

=item accountType

Type of account to be authenticated.

Defaults to 'HOSTED_OR_GOOGLE'.

=back

See http://code.google.com/apis/accounts/AuthForInstalledApps.html#ClientLogin for more details.

=cut


our %BUGS = (
    'not_dopplr_any_more' => {
        'cuddled'       => 1,
        'json_response' => 1,
    },
);

sub new {
    my $class  = shift;
    my %params = @_;

    $params{_ua}           = LWP::UserAgent->new;    
    $params{_ua}->env_proxy;
    $params{url}         ||= 'https://www.google.com/accounts';
    $params{service}     ||= 'xapi';
    $params{source}      ||= $APP_NAME;
    $params{accountType} ||= 'HOSTED_OR_GOOGLE';
    $params{_compat}     ||= {};

    my $site = delete $params{_bug_compat};
    if (defined $site && exists $BUGS{$site}) {
        foreach my $key (keys %{$BUGS{$site}}) {
            $params{_compat}->{$key} = $BUGS{$site}->{$key};
        }
    }


    return bless \%params, $class;
}

=head2 login <username> <password> [opt[s]]

Login to google using your username and password.

Can optionally take a hash of options which will override the 
default login params. 

Returns a C<Net::Google::AuthSub::Response> object.

=cut

sub login {
    my ($self, $user, $pass, %opts) = @_;

    # setup auth request
    my %params = ( Email       => $user, 
                   Passwd      => $pass, 
                   service     => $self->{service}, 
                   source      => $self->{source},
                   accountType => $self->{accountType} );
    # allow overrides
    $params{$_} = $opts{$_} for (keys %opts);


    my $uri = URI->new($self->{url});
    $uri->path($uri->path.'/ClientLogin');
    my $tmp = $self->{_ua}->request(POST "$uri", [ %params ]);
    return $self->_response_failure($tmp) unless $tmp->is_success;
    my $r = Net::Google::AuthSub::Response->new($tmp, $self->{url}, _compat => $self->{_compat});


    # store auth token
    $self->{_auth}      = $r->auth;
    $self->{_auth_type} = CLIENT_LOGIN;
    $self->{user}       = $user;
    $self->{pass}       = $pass; 
    return $r;

}

sub _response_failure {
    my $self = shift;
    my $r    = shift;
    $@ = $r->content;   
    return Net::Google::AuthSub::Response->new(
        $r,
        $self->{url},
        _compat => $self->{_compat}
    ); }


=head2 authorised 

Whether or not we're authorised.

=cut

sub authorised {
    my $self = shift;
    return defined $self->{_auth};

}

=head2 authorized 

An alias for authorized.

=cut
*authorized = \&authorised;

=head2 auth <username> <token>

Use the AuthSub method for access.

See http://code.google.com/apis/accounts/AuthForWebApps.html 
for details.

=cut

sub auth {
    my ($self, $username, $token) = @_;
    $self->{_auth}      = $token;
    $self->{_auth_type} = AUTH_SUB;
    $self->{user}       = $username;
    return 1;
}

=head2 auth_token [token] 

Get or set the current auth token

=cut
sub auth_token {
    my $self = shift;
    $self->{_auth} = shift if @_;
    return $self->{_auth};
}

=head2 auth_type [type]

Get or set the current auth type

Returns either C<$Net::Google::AuthSub::CLIENT_LOGIN> or 
C<$Net::Google::AuthSub::AUTH_SUB>.

=cut
sub auth_type {
    my $self = shift;
    $self->{_auth_type} = shift if @_;
    return $self->{_auth_type};
}

=head2 request_token <next> <scope> [option[s]]

Return a URI object representing the URL which the user 
should be directed to in order to aquire a single use token.

The parameters are 

=over 4

=item next (required)

URL the user should be redirected to after a successful login. 
This value should be a page on the web application site, and 
can include query parameters.

=item scope (required)

URL identifying the service to be accessed. The resulting token 
will enable access to the specified service only. Some services 
may limit scope further, such as read-only access.

For example

    http://www.google.com/calendar/feed

=item secure

Boolean flag indicating whether the authentication transaction 
should issue a secure token (1) or a non-secure token (0). 
Secure tokens are available to registered applications only.

=item session

Boolean flag indicating whether the one-time-use token may be 
exchanged for a session token (1) or not (0).

=back

=cut

sub request_token {
    my $self = shift;
    my ($next, $scope, %opts) = @_;
    $opts{next}  = $next;
    $opts{scope} = $scope;

    my $uri = URI->new($self->{url});

    $uri->path($uri->path.'/AuthSubRequest');
    $uri->query_form(%opts);
    return $uri;
}


=head2 session_token

Exchange the temporary token for a long-lived session token.

The single-use token is acquired by visiting the url generated by
calling request_token.

Returns the token if success and undef if failure.

=cut

sub session_token {
    my $self = shift;

    my $uri = URI->new($self->{url});
    $uri->path($uri->path.'/AuthSubSessionToken');

    my %params = $self->auth_params();
    my $tmp    = $self->{_ua}->request(GET "$uri", %params);
    return $self->_response_failure($tmp) unless $tmp->is_success;    
    my $r      = Net::Google::AuthSub::Response->new($tmp, $self->{url}, _compat => $self->{_compat});

    # store auth token
    $self->{_auth}      = $r->token;
    
    return $r->token;
}

=head2 revoke_token

Revoke a valid session token. Session tokens have no expiration date and 
will remain valid unless revoked.

Returns 1 if success and undef if failure.

=cut

sub revoke_token {
    my $self = shift;

    my $uri = URI->new($self->{url});
    $uri->path($uri->path.'/AuthSubRevokeToken');

    my %params = $self->auth_params();
    my $r      = $self->{_ua}->request(GET "$uri", [ %params ]);
    return $self->_response_error($r) unless $r->is_success;
    return 1;

}

=head2 token_info

Call AuthSubTokenInfo to test whether a given session token is valid. 
This method validates the token in the same way that a Google service 
would; application developers can use this method to verify that their 
application is getting valid tokens and handling them appropriately 
without involving a call to the Google service. It can also be used to 
get information about the token, including next URL, scope, and secure 
status, as specified in the original token request.

Returns a C<Net::Google::AuthSub::Response> object on success or undef on failure.

=cut

sub token_info {
    my $self = shift;

    my $uri = URI->new($self->{url});
    $uri->path($uri->path.'/AuthSubTokenInfo');

    my %params = $self->auth_params();
    my $tmp    = $self->{_ua}->request(GET "$uri", [ %params ]);
    my $r      = Net::Google::AuthSub::Response->new($tmp, $self->{url}, _compat => $self->{_compat});    
    return $self->_response_failure($r) unless $r->is_success;
    return $r;
} 

=head2 auth_params

Return any parameters needed in an HTTP request to authorise your app.

=cut

sub auth_params {
    my $self  = shift;

    return () unless $self->authorised;
    return ( Authorization => $self->_auth_string );
}

my %AUTH_TYPES = ( CLIENT_LOGIN() => "GoogleLogin auth", AUTH_SUB() => "AuthSub token" );

sub _auth_string {
    my $self   = shift;
    return "" unless $self->authorised;
    if ($self->{_compat}->{uncuddled_auth}) {
        return sprintf '%s=%s', $AUTH_TYPES{$self->{_auth_type}}, $self->{_auth};
    } else {
        return sprintf '%s="%s"', $AUTH_TYPES{$self->{_auth_type}}, $self->{_auth};        
    }
}


=head1 AUTHOR

Simon Wistow <simon@thegestalt.org>

=head1 COPYRIGHT

Copyright, 2007 - Simon Wistow

Released under the same terms as Perl itself

=cut


1;