This repository has been archived by the owner on Jan 17, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathExtension.pm
171 lines (139 loc) · 5.45 KB
/
Extension.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#-------------------------------------------------------------------------------
#
# This file is part of Bugzilla-OpenID.
#
# Copyright (C) 2012 Jacky Alciné <jackyalcine@gmail.com>
#
# Bugzilla-OpenID is free software; you can redistribute it and/or
# modify it under the terms of the GNU Library General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# Bugzilla-OpenID is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Library General Public License for more details.
#
# You should have received a copy of the GNU Library General Public
# License along with Bugzilla-OpenID.
# If not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# @author Jacky Alciné <jackyalcine@gmail.com>
# @date 04/23/12 9:41:00 AM
#
#
#-------------------------------------------------------------------------------
package Bugzilla::Extension::OpenID;
use strict;
use warnings;
use Bugzilla::User;
use Bugzilla::Util qw(correct_urlbase);
use Bugzilla::Extension::OpenID::Util qw(get_identity);
use base qw(Bugzilla::Extension);
our $VERSION = '0.1';
sub auth_login_methods {
my ($self, $args) = @_;
my $modules = $args->{modules};
if (exists $modules->{OpenID}) {
$modules->{OpenID} = 'Bugzilla/Extension/OpenID/Auth/Login.pm';
}
}
sub config_add_panels {
my ($self, $args) = @_;
my $modules = $args->{panel_modules};
$modules->{OpenID} = "Bugzilla::Extension::OpenID::Config";
}
# NOTE: Should OpenID provide verification schemes?
sub config_modify_panels {
my ($self, $args) = @_;
my $panels = $args->{'panels'};
my $auth_panel_params = $panels->{'auth'}->{'params'};
my ($user_info_class) =
grep { $_->{'name'} eq 'user_info_class' } @$auth_panel_params;
if ($user_info_class) {
push(@{ $user_info_class->{'choices'} }, "OpenID,CGI");
}
}
# TODO: Devise a proper schema for OpenID.
sub db_schema_abstract_schema {
my ($self, $args) = @_;
#$args->{'schema'}->{'OpenID'} = {};
}
# TODO: Devise a proper setup for user configuration.
sub user_preferences {
my ($self, $args) = @_;
my $tab = $args->{current_tab};
my $save = $args->{save_changes};
my $handled = $args->{handled};
return unless $tab eq 'openid_tab';
my $idUrl = Bugzilla->input_params->{'openid_pref_url'};
if ($save) {
# TODO: Add validation for valid Urls.
$idUrl =~ s/\s+/:/g;
}
$args->{'vars'}->{openid_pref_url} = $idUrl;
# Set the 'handled' scalar reference to true so that the caller
# knows the panel name is valid and that an extension took care of it.
$$handled = 1;
}
sub page_before_template {
my ($self,$args) = @_;
my $cgi = Bugzilla->cgi();
my $page_id = $args->{'page_id'};
my $vars = $args->{'vars'};
my $cident = undef;
if ($page_id eq "openid_continue.html"){
$vars->{'mode'} = $cgi->param('mode');
$vars->{openid_redirect_base} = $args->{'redirect_to'};
if ($vars->{'mode'} eq 'authenticate'){
$vars->{'openid_url'} = $cgi->param('openid_url');
}
} elsif ($page_id eq 'openid_authenticate.html') {
$vars->{'stage'} = $cgi->param('stage');
if ($vars->{'stage'} eq 'handle'){
$vars->{'redirect_to'} = $cgi->param('redirect_to');
$vars->{'openid_url'} = $cgi->param('openid_url');
my $cident = Bugzilla::Extension::OpenID::Util->get_identity($vars->{'openid_url'});
if ($cident->{'claimed'} eq 1){
my $ident = $cident->{'identity'};
$ident = $$ident;
# Set up some extra values to ensure that this OpenID is compatible.
# TODO: Allow the privacy policy URL to be modified.
$ident->set_extension_args('http://openid.net/extensions/sreg/1.1',
{
required => 'email,fullname',
policy_url => correct_urlbase() . "/page.cgi?id=openid_policy.html"
}
);
# TODO: Allow the Bugzilla admin specify the trust_root value.
my $openid_auth_url = $ident->check_url(
delayed_return => 1,
return_to => correct_urlbase() . "/page.cgi?id=openid_authenticate.html&stage=claim&redirect_to=" . $vars->{'redirect_to'},
trust_root => correct_urlbase()
);
$vars->{'openid_url'} = $ident->claimed_url();
$vars->{'redirect_auth'} = $openid_auth_url;
$vars->{'stage'} = "continue";
} else {
$vars->{'stage'} = "error";
$vars->{'error_message'} = $cident->{'error'};
}
}
}
}
# TODO: In the future, provide a service permitting OpenID-based log-ins.
#sub webservice {
# my ($self, $args) = @_;
#
# my $dispatch = $args->{dispatch};
# $dispatch->{OpenID} = "Bugzilla::Extension::OpenID::WebService";
#}
#sub webservice_error_codes {
# my ($self, $args) = @_;
#
# my $error_map = $args->{error_map};
# $error_map->{'openid_general_error'} = 10001;
# }
# This must be the last line of your extension.
__PACKAGE__->NAME;