summaryrefslogtreecommitdiffstats
path: root/extensions/GitHubAuth/Extension.pm
diff options
context:
space:
mode:
authorDylan William Hardison <dylan@hardison.net>2015-03-04 04:27:15 +0100
committerDylan William Hardison <dylan@hardison.net>2015-04-03 00:21:08 +0200
commitc0d00a57eebb31d3e2cdef0ebb9219ebe2fe2bab (patch)
treee6c6eb07c7348e086f1ed6de54de829e806dda05 /extensions/GitHubAuth/Extension.pm
parent1317be9bb70dbb945fa82d0d1bd8548c83c86ebe (diff)
downloadbugzilla-c0d00a57eebb31d3e2cdef0ebb9219ebe2fe2bab.tar.gz
bugzilla-c0d00a57eebb31d3e2cdef0ebb9219ebe2fe2bab.tar.xz
Github Auth Extension
Diffstat (limited to 'extensions/GitHubAuth/Extension.pm')
-rw-r--r--extensions/GitHubAuth/Extension.pm94
1 files changed, 94 insertions, 0 deletions
diff --git a/extensions/GitHubAuth/Extension.pm b/extensions/GitHubAuth/Extension.pm
new file mode 100644
index 000000000..dee927165
--- /dev/null
+++ b/extensions/GitHubAuth/Extension.pm
@@ -0,0 +1,94 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+# This Source Code Form is "Incompatible With Secondary Licenses", as
+# defined by the Mozilla Public License, v. 2.0.
+
+package Bugzilla::Extension::GitHubAuth;
+
+use 5.10.1;
+use strict;
+use parent qw(Bugzilla::Extension);
+
+use Bugzilla::Extension::GitHubAuth::Client;
+use Bugzilla::Extension::GitHubAuth::Util qw(target_uri);
+
+use Bugzilla::Error;
+use Bugzilla::Util qw(trick_taint);
+use List::Util qw(first);
+use URI;
+use URI::QueryParam;
+
+our $VERSION = '0.01';
+
+BEGIN {
+ # Monkey-patch can() on Bugzilla::Auth::Login::CGI so that our own fail_nodata gets called.
+ # Our fail_nodata behaves like CGI's, so this shouldn't be a problem for CGI-based logins.
+
+ *Bugzilla::Auth::Login::CGI::can = sub {
+ my ($stack, $method) = @_;
+
+ return undef if $method eq 'fail_nodata';
+ return $stack->UNIVERSAL::can($method);
+ };
+}
+
+sub install_before_final_checks {
+ Bugzilla::Group->create({
+ name => 'no-github-auth',
+ description => 'Group containing groups whose members may not use GitHubAuth to log in',
+ isbuggroup => 0,
+ }) unless Bugzilla::Group->new({ name => 'no-github-auth' });
+}
+
+sub template_before_create {
+ my ($self, $args) = @_;
+
+ return if Bugzilla->user->id && !Bugzilla->cgi->param('logout');
+
+ $args->{config}{VARIABLES}{github_auth} = {
+ login => sub {
+ return Bugzilla::Extension::GitHubAuth::Client->login_uri(target_uri());
+ },
+ };
+}
+
+sub auth_login_methods {
+ my ($self, $args) = @_;
+ my $modules = $args->{'modules'};
+ if (exists $modules->{'GitHubAuth'}) {
+ $modules->{'GitHubAuth'} = 'Bugzilla/Extension/GitHubAuth/Login.pm';
+ }
+}
+
+sub auth_verify_methods {
+ my ($self, $args) = @_;
+ my $modules = $args->{'modules'};
+ if (exists $modules->{'GitHubAuth'}) {
+ $modules->{'GitHubAuth'} = 'Bugzilla/Extension/GitHubAuth/Verify.pm';
+ }
+}
+
+sub config_modify_panels {
+ my ($self, $args) = @_;
+ my $auth_panel_params = $args->{panels}{auth}{params};
+
+ my $user_info_class = first { $_->{name} eq 'user_info_class' } @$auth_panel_params;
+ if ($user_info_class) {
+ push @{ $user_info_class->{choices} }, "GitHubAuth,CGI", "Persona,GitHubAuth,CGI";
+ }
+
+ my $user_verify_class = first { $_->{name} eq 'user_verify_class' } @$auth_panel_params;
+ if ($user_verify_class) {
+ unshift @{ $user_verify_class->{choices} }, "GitHubAuth";
+ }
+}
+
+sub config_add_panels {
+ my ($self, $args) = @_;
+ my $modules = $args->{panel_modules};
+ $modules->{GitHubAuth} = "Bugzilla::Extension::GitHubAuth::Config";
+}
+
+__PACKAGE__->NAME;