File Coverage

lib/LWP/Authen/OAuth2/ServiceProvider/Google.pm
Criterion Covered Total %
statement 21 35 60.0
branch 1 2 50.0
condition n/a
subroutine 11 19 57.8
pod 3 5 60.0
total 36 61 59.0


line stmt bran cond sub pod time code
1             package LWP::Authen::OAuth2::ServiceProvider::Google;
2              
3             # ABSTRACT: Google OAuth2
4             our $VERSION = '0.20'; # VERSION
5              
6 1     1   918 use strict;
  1         2  
  1         31  
7 1     1   5 use warnings;
  1         3  
  1         761  
8              
9             our @ISA = qw(LWP::Authen::OAuth2::ServiceProvider);
10              
11             sub authorization_endpoint {
12 1     1 1 11 return "https://accounts.google.com/o/oauth2/auth";
13             }
14              
15             sub token_endpoint {
16 1     1 1 7 return "https://accounts.google.com/o/oauth2/token";
17             }
18              
19             sub authorization_required_params {
20 1     1 0 2 my $self = shift;
21 1         5 return ("scope", $self->SUPER::authorization_required_params());
22             }
23              
24             sub authorization_optional_params {
25 1     1 0 2 my $self = shift;
26 1         15 return ("login_hint", $self->SUPER::authorization_optional_params());
27             }
28              
29             my %client_type_class
30             = (
31             default => "WebServer",
32             device => "Device",
33             installed => "Installed",
34             login => "Login",
35             "web server" => "WebServer",
36             service => "Service",
37             );
38              
39             sub client_type_class {
40 1     1 1 3 my ($class, $client_type) = @_;
41 1 50       3 if (exists $client_type_class{$client_type}) {
42 1         6 return "LWP::Authen::OAuth2::ServiceProvider::Google::$client_type_class{$client_type}";
43             }
44             else {
45 0         0 my $allowed = join ", ", sort keys %client_type_class;
46 0         0 Carp::croak("Flow '$client_type' not in: $allowed");
47             }
48             }
49              
50             package LWP::Authen::OAuth2::ServiceProvider::Google::Device;
51             our @ISA = qw(LWP::Authen::OAuth2::ServiceProvider::Google);
52              
53             sub init {
54 0     0   0 Carp::confess(__PACKAGE__ . " is not implemented.");
55             }
56              
57             package LWP::Authen::OAuth2::ServiceProvider::Google::Installed;
58             our @ISA = qw(LWP::Authen::OAuth2::ServiceProvider::Google);
59              
60             sub init {
61 0     0   0 Carp::confess(__PACKAGE__ . " is not implemented.");
62             }
63              
64             package LWP::Authen::OAuth2::ServiceProvider::Google::Login;
65             our @ISA = qw(LWP::Authen::OAuth2::ServiceProvider::Google);
66              
67             sub init {
68 0     0   0 Carp::confess(__PACKAGE__ . " is not implemented.");
69             }
70              
71             sub authorization_required_params {
72 0     0   0 my $self = shift;
73 0         0 return ("state", $self->SUPER::authorization_required_params());
74             }
75              
76             sub authorization_default_params {
77 0     0   0 my $self = shift;
78             return (
79 0         0 "scope" => "openid email",
80             $self->SUPER::authorization_default_params()
81             );
82             }
83              
84             sub request_required_params {
85 0     0   0 my $self = shift;
86 0         0 return ("state", $self->SUPER::request_required_params());
87             }
88              
89             sub request_default_params {
90 0     0   0 my $self = shift;
91             return (
92 0         0 "scope" => "openid email",
93             $self->SUPER::request_default_params()
94             );
95             }
96              
97             package LWP::Authen::OAuth2::ServiceProvider::Google::Service;
98             our @ISA = qw(LWP::Authen::OAuth2::ServiceProvider::Google);
99              
100             sub init {
101 0     0   0 Carp::confess(__PACKAGE__ . " is not implemented.");
102             }
103              
104             package LWP::Authen::OAuth2::ServiceProvider::Google::WebServer;
105             our @ISA = qw(LWP::Authen::OAuth2::ServiceProvider::Google);
106              
107             # Not guaranteed a refresh token, so require nothing.
108             sub required_init {
109 1     1   5 return ();
110             }
111              
112             sub optional_init {
113 1     1   5 return qw(redirect_uri scope client_id client_secret);
114             }
115              
116             sub authorization_optional_params {
117 1     1   2 my $self = shift;
118             return (
119 1         7 "access_type", "approval_prompt",
120             $self->SUPER::authorization_optional_params()
121             );
122             }
123              
124             sub request_required_params {
125 1     1   2 my $self = shift;
126 1         7 return ("redirect_uri", $self->SUPER::request_required_params());
127             }
128              
129              
130             1;
131              
132             __END__