/[drupal]/contributions/modules/openid_provider/openid_provider.module
ViewVC logotype

Contents of /contributions/modules/openid_provider/openid_provider.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.3 - (show annotations) (download) (as text)
Sun Sep 7 03:51:58 2008 UTC (14 months, 2 weeks ago) by walkah
Branch: MAIN
CVS Tags: HEAD
Branch point for: DRUPAL-6--1
Changes since 1.2: +10 -3 lines
File MIME type: text/x-php
#302951 : patch by christefano (modified by me) to restrict access to
 the "OpenID Sites" tab for unprivileged users.
1 <?php
2 // $Id: openid_provider.module,v 1.2 2008/09/07 03:39:57 walkah Exp $
3
4 /**
5 * OpenID 2.0 Provider implementation for Drupal.
6 */
7
8 /**
9 * Implementation of hook_perm().
10 */
11 function openid_provider_perm() {
12 return array('administer openid');
13 }
14
15 /**
16 * Implementation of hook_menu().
17 */
18 function openid_provider_menu() {
19 $items['admin/settings/openid_provider'] = array(
20 'title' => 'OpenID Provider',
21 'description' => 'Configure settings for the OpenID Provider.',
22 'page callback' => 'drupal_get_form',
23 'page arguments' => array('openid_provider_admin_settings'),
24 'access arguments' => array('administer openid'),
25 'type' => MENU_NORMAL_ITEM,
26 );
27
28 $items['openid/provider'] = array(
29 'title' => 'OpenID Login',
30 'page callback' => 'openid_provider_endpoint',
31 'access callback' => TRUE,
32 'type' => MENU_CALLBACK,
33 'file' => 'openid_provider.pages.inc'
34 );
35
36 $items['openid/provider/send'] = array(
37 'title' => 'OpenID Login',
38 'page callback' => 'openid_provider_send',
39 'access callback' => TRUE,
40 'type' => MENU_CALLBACK,
41 'file' => 'openid_provider.pages.inc'
42 );
43
44 $items['openid/provider/continue'] = array(
45 'title' => 'OpenID Login',
46 'page callback' => 'openid_provider_continue',
47 'access callback' => TRUE,
48 'type' => MENU_CALLBACK,
49 'file' => 'openid_provider.pages.inc'
50 );
51
52 $items['user/%user/openid_sites'] = array(
53 'title' => 'OpenID Sites',
54 'page callback' => 'openid_provider_sites',
55 'page arguments' => array(1),
56 'access callback' => 'openid_provider_sites_access',
57 'access arguments' => array(1),
58 'type' => MENU_LOCAL_TASK,
59 'file' => 'openid_provider.pages.inc'
60 );
61
62 return $items;
63 }
64
65 /**
66 * Implementation of hook_init()
67 *
68 * Add appropriate HTML headers for XRDS and Link discovery.
69 */
70 function openid_provider_init() {
71 // Not all OpenID clients may be smart enough to do XRDS.
72 drupal_add_link(array('rel' => 'openid2.provider', 'href' => url('openid/provider', array('absolute' => TRUE))));
73 drupal_add_link(array('rel' => 'openid.server', 'href' => url('openid/provider', array('absolute' => TRUE))));
74 }
75
76 function openid_provider_sites_access($account) {
77 global $user;
78
79 return ($account->uid == $user->uid) || user_access('administer openid');
80 }
81
82 /**
83 * Implementation of hook_user.
84 */
85 function openid_provider_user($op, &$edit, &$account, $category = NULL) {
86 global $user;
87
88 switch ($op) {
89 case 'view':
90 if ($user->uid == $account->uid) {
91 $account->content['openid'] = array(
92 '#title' => t('OpenID'),
93 '#value' => t('You may login to other OpenID enabled sites using %url', array('%url' => url('user/' . $account->uid, array('absolute' => TRUE)))),
94 '#class' => 'openid',
95 '#weight' => 10
96 );
97 }
98 break;
99 }
100 }
101
102 /**
103 * Settings form.
104 */
105 function openid_provider_admin_settings() {
106 $form = array();
107 $form['openid_provider_assoc_expires_in'] = array(
108 '#type' => 'textfield',
109 '#title' => t('Associations expire in this many seconds'),
110 '#default_value' => variable_get('openid_provider_assoc_expires_in', '3600'),
111 '#size' => 10,
112 '#maxlength' => 10);
113 return system_settings_form($form);
114 }
115
116 /**
117 * Return a XRDS for this server to discover it based on the root url
118 */
119 function openid_provider_xrds($account = NULL) {
120 module_load_include('inc', 'openid');
121
122 if ($account) {
123 $types = array(OPENID_NS_2_0 .'/signon');
124 }
125 else {
126 $types = array(OPENID_NS_2_0 .'/server');
127 }
128
129 $data = array(
130 'Type' => $types,
131 'URI' => array(url('openid/provider', array('absolute'=> TRUE))),
132 );
133 if ($account->uid) {
134 $data['LocalID'] = array(url('user/'. $account->uid, array('absolute' => TRUE)));
135 }
136
137 $xrds['openid_provider'] = array(
138 'services' => array(
139 array('priority' => 10,
140 'data' => $data
141 )
142 )
143 );
144
145 return $xrds;
146 }
147
148 /**
149 * Main OpenID Provider form
150 */
151 function openid_provider_form(&$form_state, &$response = array(), $realm = NULL) {
152 global $user;
153
154 // Use form_state to store the $response and $realm values
155 if (count($response)) {
156 $form_state['storage']['response'] = $response;
157 }
158 else {
159 $response = $form_state['storage']['response'];
160 }
161
162 if ($realm) {
163 $form_state['storage']['realm'] = $realm;
164 }
165 else {
166 $realm = $form_state['storage']['realm'];
167 }
168
169 $form = array();
170
171 $form['intro'] = array(
172 '#type' => 'markup',
173 '#value' => '<p>'. t('You are being logged into %site, would you like to continue?', array('%site' => $realm)) . '</p>'
174 );
175
176 $form['#action'] = url('openid/provider/send');
177
178 $form['submit_once'] = array(
179 '#type' => 'submit',
180 '#value' => t('Yes; just this once'),
181 );
182 $form['submit_always'] = array(
183 '#type' => 'submit',
184 '#value' => t('Yes; always'),
185 '#submit' => array('openid_provider_form_submit_always')
186 );
187 $form['cancel'] = array(
188 '#type' => 'submit',
189 '#value' => t('Cancel'),
190 '#submit' => array('openid_provider_form_submit_cancel')
191 );
192
193 return $form;
194 }
195
196 /**
197 * Once submit handler
198 */
199 function openid_provider_form_submit(&$form, $form_state, $auto_release = FALSE) {
200 global $user;
201
202 module_load_include('inc', 'openid');
203 module_load_include('inc', 'openid_provider');
204
205 $response = _openid_provider_sign($form_state['storage']['response']);
206 _openid_provider_rp_save($user->uid, $form_state['storage']['realm'], $auto_release);
207 openid_redirect_http($response['openid.return_to'], $response);
208 }
209
210 /**
211 * Always submit handler
212 */
213 function openid_provider_form_submit_always(&$form, $form_state) {
214 return openid_provider_form_submit($form, $form_state, TRUE);
215 }
216
217 /**
218 * Cancel submit handler
219 */
220 function openid_provider_form_submit_cancel(&$form, $form_state) {
221 module_load_include('inc', 'openid_provider');
222 module_load_include('inc', 'openid');
223
224 $return_to = $form_state['values']['openid.return_to'];
225 $response = openid_provider_cancel_authentication_response($form_state['openid.mode']);
226 openid_redirect($return_to, $response);
227 }

  ViewVC Help
Powered by ViewVC 1.1.2