| 1 | package WWW::Google::API::Account::ProgrammaticLogin; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use warnings; | ||
| 5 | |||
| 6 | use base qw(WWW::Google::API::Account); | ||
| 7 | |||
| 8 | sub authenticate { | ||
| 9 | my $self = shift; | ||
| 10 | my $conn = shift; | ||
| 11 | |||
| 12 | my $auth_token = undef; | ||
| 13 | my $client_login_uri = 'https://www.google.com/accounts/clientlogin'; | ||
| 14 | |||
| 15 | $self->ua->default_header( 'content-type' => 'application/x-www-form-urlencoded' ); | ||
| 16 | |||
| 17 | my $response = $self->ua->post( $client_login_uri, | ||
| 18 | { accountType => 'hosted_or_google', | ||
| 19 | Email => $conn->{api_user}, | ||
| 20 | Passwd => $conn->{api_pass}, | ||
| 21 | service => $conn->{service}, | ||
| 22 | } | ||
| 23 | ); | ||
| 24 | |||
| 25 | if ( $response->is_success ) { | ||
| 26 | my $content = $response->content; | ||
| 27 | my @content = split("\n", $content); | ||
| 28 | for ( @content ) { | ||
| 29 | $auth_token = $1 if /^Auth=(.*)$/; | ||
| 30 | } | ||
| 31 | } else { | ||
| 32 | die $response->status_line; | ||
| 33 | } | ||
| 34 | |||
| 35 | return $auth_token; | ||
| 36 | } | ||
| 37 | |||
| 38 | 1; |