diff options
author | Perl Tidy <perltidy@bugzilla.org> | 2018-12-05 21:38:52 +0100 |
---|---|---|
committer | Dylan William Hardison <dylan@hardison.net> | 2018-12-05 23:49:08 +0100 |
commit | 8ec8da0491ad89604700b3e29a227966f6d84ba1 (patch) | |
tree | 9d270f173330ca19700e0ba9f2ee931300646de1 /extensions/GitHubAuth/lib/Client.pm | |
parent | a7bb5a65b71644d9efce5fed783ed545b9336548 (diff) | |
download | bugzilla-8ec8da0491ad89604700b3e29a227966f6d84ba1.tar.gz bugzilla-8ec8da0491ad89604700b3e29a227966f6d84ba1.tar.xz |
no bug - reformat all the code using the new perltidy rules
Diffstat (limited to 'extensions/GitHubAuth/lib/Client.pm')
-rw-r--r-- | extensions/GitHubAuth/lib/Client.pm | 134 |
1 files changed, 68 insertions, 66 deletions
diff --git a/extensions/GitHubAuth/lib/Client.pm b/extensions/GitHubAuth/lib/Client.pm index 291501961..328bab48f 100644 --- a/extensions/GitHubAuth/lib/Client.pm +++ b/extensions/GitHubAuth/lib/Client.pm @@ -16,7 +16,8 @@ use URI; use URI::QueryParam; use Digest; -use Bugzilla::Extension::GitHubAuth::Client::Error qw(ThrowUserError ThrowCodeError); +use Bugzilla::Extension::GitHubAuth::Client::Error + qw(ThrowUserError ThrowCodeError); use Bugzilla::Util qw(remote_ip); use constant DIGEST_HASH => 'SHA1'; @@ -24,107 +25,108 @@ use constant DIGEST_HASH => 'SHA1'; use fields qw(user_agent); use constant { - GH_ACCESS_TOKEN_URI => 'https://github.com/login/oauth/access_token', - GH_AUTHORIZE_URI => 'https://github.com/login/oauth/authorize', - GH_USER_EMAILS_URI => 'https://api.github.com/user/emails', + GH_ACCESS_TOKEN_URI => 'https://github.com/login/oauth/access_token', + GH_AUTHORIZE_URI => 'https://github.com/login/oauth/authorize', + GH_USER_EMAILS_URI => 'https://api.github.com/user/emails', }; sub new { - my ($class, %init) = @_; - my $self = $class->fields::new(); + my ($class, %init) = @_; + my $self = $class->fields::new(); - return $self; + return $self; } sub login_uri { - my ($class, $target_uri) = @_; + my ($class, $target_uri) = @_; - my $uri = URI->new(Bugzilla->localconfig->{urlbase} . "github.cgi"); - $uri->query_form(target_uri => $target_uri); - return $uri; + my $uri = URI->new(Bugzilla->localconfig->{urlbase} . "github.cgi"); + $uri->query_form(target_uri => $target_uri); + return $uri; } sub authorize_uri { - my ($class, $state) = @_; + my ($class, $state) = @_; - my $uri = URI->new(GH_AUTHORIZE_URI); - $uri->query_form( - client_id => Bugzilla->params->{github_client_id}, - scope => 'user:email', - state => $state, - redirect_uri => Bugzilla->localconfig->{urlbase} . "github.cgi", - ); + my $uri = URI->new(GH_AUTHORIZE_URI); + $uri->query_form( + client_id => Bugzilla->params->{github_client_id}, + scope => 'user:email', + state => $state, + redirect_uri => Bugzilla->localconfig->{urlbase} . "github.cgi", + ); - return $uri; + return $uri; } sub get_email_key { - my ($class, $email) = @_; - - my $cgi = Bugzilla->cgi; - my $digest = Digest->new(DIGEST_HASH); - $digest->add($email); - $digest->add(remote_ip()); - $digest->add($cgi->cookie('Bugzilla_github_token') // Bugzilla->request_cache->{github_token} // ''); - $digest->add(Bugzilla->localconfig->{site_wide_secret}); - return $digest->hexdigest; + my ($class, $email) = @_; + + my $cgi = Bugzilla->cgi; + my $digest = Digest->new(DIGEST_HASH); + $digest->add($email); + $digest->add(remote_ip()); + $digest->add($cgi->cookie('Bugzilla_github_token') + // Bugzilla->request_cache->{github_token} // ''); + $digest->add(Bugzilla->localconfig->{site_wide_secret}); + return $digest->hexdigest; } sub _handle_response { - my ($self, $response) = @_; - my $data = eval { - decode_json($response->content); - }; - if ($@) { - ThrowCodeError("github_bad_response", { message => "Unable to parse json response" }); - } - - unless ($response->is_success) { - ThrowCodeError("github_error", { response => $response }); - } - return $data; + my ($self, $response) = @_; + my $data = eval { decode_json($response->content); }; + if ($@) { + ThrowCodeError("github_bad_response", + {message => "Unable to parse json response"}); + } + + unless ($response->is_success) { + ThrowCodeError("github_error", {response => $response}); + } + return $data; } sub get_access_token { - my ($self, $code) = @_; - - my $response = $self->user_agent->post( - GH_ACCESS_TOKEN_URI, - { client_id => Bugzilla->params->{github_client_id}, - client_secret => Bugzilla->params->{github_client_secret}, - code => $code }, - Accept => 'application/json', - ); - my $data = $self->_handle_response($response); - return $data->{access_token} if exists $data->{access_token}; + my ($self, $code) = @_; + + my $response = $self->user_agent->post(GH_ACCESS_TOKEN_URI, + { + client_id => Bugzilla->params->{github_client_id}, + client_secret => Bugzilla->params->{github_client_secret}, + code => $code + }, + Accept => 'application/json', + ); + my $data = $self->_handle_response($response); + return $data->{access_token} if exists $data->{access_token}; } sub get_user_emails { - my ($self, $access_token) = @_; - my $uri = URI->new(GH_USER_EMAILS_URI); - $uri->query_form(access_token => $access_token); + my ($self, $access_token) = @_; + my $uri = URI->new(GH_USER_EMAILS_URI); + $uri->query_form(access_token => $access_token); - my $response = $self->user_agent->get($uri, Accept => 'application/json'); + my $response = $self->user_agent->get($uri, Accept => 'application/json'); - return $self->_handle_response($response); + return $self->_handle_response($response); } sub user_agent { - my ($self) = @_; - $self->{user_agent} //= $self->_build_user_agent; + my ($self) = @_; + $self->{user_agent} //= $self->_build_user_agent; - return $self->{user_agent}; + return $self->{user_agent}; } sub _build_user_agent { - my ($self) = @_; - my $ua = LWP::UserAgent->new( timeout => 10 ); + my ($self) = @_; + my $ua = LWP::UserAgent->new(timeout => 10); - if (Bugzilla->params->{proxy_url}) { - $ua->proxy('https', Bugzilla->params->{proxy_url}); - } + if (Bugzilla->params->{proxy_url}) { + $ua->proxy('https', Bugzilla->params->{proxy_url}); + } - return $ua; + return $ua; } 1; |