« blib/lib/LWP/Authen/OAuth2/ServiceProvider/Line.pm
↑ Summary
lib/LWP/Authen/OAuth2/ServiceProvider/Dwolla.pm »
| 1 | package LWP::Authen::OAuth2::ServiceProvider::Google; | ||
| 2 | |||
| 3 | # ABSTRACT: Google OAuth2 | ||
| 4 | our $VERSION = '0.18'; # VERSION | ||
| 5 | |||
| 6 | use strict; | ||
| 7 | use warnings; | ||
| 8 | |||
| 9 | our @ISA = qw(LWP::Authen::OAuth2::ServiceProvider); | ||
| 10 | |||
| 11 | sub authorization_endpoint { | ||
| 12 | return "https://accounts.google.com/o/oauth2/auth"; | ||
| 13 | } | ||
| 14 | |||
| 15 | sub token_endpoint { | ||
| 16 | return "https://accounts.google.com/o/oauth2/token"; | ||
| 17 | } | ||
| 18 | |||
| 19 | sub authorization_required_params { | ||
| 20 | my $self = shift; | ||
| 21 | return ("scope", $self->SUPER::authorization_required_params()); | ||
| 22 | } | ||
| 23 | |||
| 24 | sub authorization_optional_params { | ||
| 25 | my $self = shift; | ||
| 26 | 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 | my ($class, $client_type) = @_; | ||
| 41 | if (exists $client_type_class{$client_type}) { | ||
| 42 | return "LWP::Authen::OAuth2::ServiceProvider::Google::$client_type_class{$client_type}"; | ||
| 43 | } | ||
| 44 | else { | ||
| 45 | my $allowed = join ", ", sort keys %client_type_class; | ||
| 46 | 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 | 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 | 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 | Carp::confess(__PACKAGE__ . " is not implemented."); | ||
| 69 | } | ||
| 70 | |||
| 71 | sub authorization_required_params { | ||
| 72 | my $self = shift; | ||
| 73 | return ("state", $self->SUPER::authorization_required_params()); | ||
| 74 | } | ||
| 75 | |||
| 76 | sub authorization_default_params { | ||
| 77 | my $self = shift; | ||
| 78 | return ( | ||
| 79 | "scope" => "openid email", | ||
| 80 | $self->SUPER::authorization_default_params() | ||
| 81 | ); | ||
| 82 | } | ||
| 83 | |||
| 84 | sub request_required_params { | ||
| 85 | my $self = shift; | ||
| 86 | return ("state", $self->SUPER::request_required_params()); | ||
| 87 | } | ||
| 88 | |||
| 89 | sub request_default_params { | ||
| 90 | my $self = shift; | ||
| 91 | return ( | ||
| 92 | "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 | 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 | return (); | ||
| 110 | } | ||
| 111 | |||
| 112 | sub optional_init { | ||
| 113 | return qw(redirect_uri scope client_id client_secret); | ||
| 114 | } | ||
| 115 | |||
| 116 | sub authorization_optional_params { | ||
| 117 | my $self = shift; | ||
| 118 | return ( | ||
| 119 | "access_type", "approval_prompt", | ||
| 120 | $self->SUPER::authorization_optional_params() | ||
| 121 | ); | ||
| 122 | } | ||
| 123 | |||
| 124 | sub request_required_params { | ||
| 125 | my $self = shift; | ||
| 126 | return ("redirect_uri", $self->SUPER::request_required_params()); | ||
| 127 | } | ||
| 128 | |||
| 129 | |||
| 130 | 1; | ||
| 131 | |||
| 132 | __END__ |