| 1 | package PEF::Front::Oauth::Paypal; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use warnings; | ||
| 5 | use base 'PEF::Front::Oauth'; | ||
| 6 | use HTTP::Request::Common; | ||
| 7 | use feature 'state'; | ||
| 8 | use PEF::Front::Config; | ||
| 9 | |||
| 10 | sub _authorization_server { | ||
| 11 | 'https://www.paypal.com/webapps/auth/protocol/openidconnect/v1/authorize'; | ||
| 12 | } | ||
| 13 | |||
| 14 | sub _required_redirect_uri { 1 } | ||
| 15 | |||
| 16 | sub _token_request { | ||
| 17 | my ($self, $code) = @_; | ||
| 18 | my $req = POST 'https://api.paypal.com/v1/identity/openidconnect/tokenservice', | ||
| 19 | [ redirect_uri => $self->{session}->data->{oauth_redirect_uri}{$self->{service}}, | ||
| 20 | grant_type => 'authorization_code', | ||
| 21 | code => $code, | ||
| 22 | ]; | ||
| 23 | $req->authorization_basic(cfg_oauth_client_id($self->{service}), cfg_oauth_client_secret($self->{service})); | ||
| 24 | $req; | ||
| 25 | } | ||
| 26 | |||
| 27 | sub _get_user_info_request { | ||
| 28 | my ($self) = @_; | ||
| 29 | my $req = GET 'https://api.paypal.com/v1/identity/openidconnect/userinfo/?schema=openid'; | ||
| 30 | $req->content_type('application/json'); | ||
| 31 | $req->header(Authorization => 'Bearer ' . $self->{session}->data->{oauth_access_token}{$self->{service}}); | ||
| 32 | $req->header(Accept => 'application/json'); | ||
| 33 | $req; | ||
| 34 | } | ||
| 35 | |||
| 36 | sub _parse_user_info { | ||
| 37 | my ($self) = @_; | ||
| 38 | my $info = $self->{session}->data->{oauth_info_raw}{$self->{service}}; | ||
| 39 | return { | ||
| 40 | name => $info->{name} || '', | ||
| 41 | email => $info->{email} || '', | ||
| 42 | login => $info->{email} || '', | ||
| 43 | avatar => [], | ||
| 44 | }; | ||
| 45 | } | ||
| 46 | |||
| 47 | sub new { | ||
| 48 | my ($class, $self) = @_; | ||
| 49 | bless $self, $class; | ||
| 50 | } | ||
| 51 | |||
| 52 | 1; |