dolibarr 21.0.0-alpha
oauth.lib.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2012 Nicolas Villa aka Boyquotes http://informetic.fr
3 * Copyright (C) 2013 Florian Henry <florian.henry@opn-concept.pro>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 */
18
26// API access parameters OAUTH
27
34{
35 $list = array(
36 array(
37 'OAUTH_AMAZON_NAME',
38 'OAUTH_AMAZON_ID',
39 'OAUTH_AMAZON_SECRET',
40 ),
41 array(
42 'OAUTH_BITBUCKET_NAME',
43 'OAUTH_BITBUCKET_ID',
44 'OAUTH_BITBUCKET_SECRET',
45 ),
46 array(
47 'OAUTH_BITLY_NAME',
48 'OAUTH_BITLY_ID',
49 'OAUTH_BITLY_SECRET',
50 ),
51 array(
52 'OAUTH_BITRIX24_NAME',
53 'OAUTH_BITRIX24_ID',
54 'OAUTH_BITRIX24_SECRET',
55 ),
56 array(
57 'OAUTH_BOX_NAME',
58 'OAUTH_BOX_ID',
59 'OAUTH_BOX_SECRET',
60 ),
61 array(
62 'OAUTH_BUFFER_NAME',
63 'OAUTH_BUFFER_ID',
64 'OAUTH_BUFFER_SECRET',
65 ),
66 array(
67 'OAUTH_DAILYMOTION_NAME',
68 'OAUTH_DAILYMOTION_ID',
69 'OAUTH_DAILYMOTION_SECRET',
70 ),
71 array(
72 'OAUTH_DEVIANTART_NAME',
73 'OAUTH_DEVIANTART_ID',
74 'OAUTH_DEVIANTART_SECRET',
75 ),
76 array(
77 'OAUTH_DROPBOX_NAME',
78 'OAUTH_DROPBOX_ID',
79 'OAUTH_DROPBOX_SECRET',
80 ),
81 array(
82 'OAUTH_ETSY_NAME',
83 'OAUTH_ETSY_ID',
84 'OAUTH_ETSY_SECRET',
85 ),
86 array(
87 'OAUTH_EVEONLINE_NAME',
88 'OAUTH_EVEONLINE_ID',
89 'OAUTH_EVEONLINE_SECRET',
90 ),
91 array(
92 'OAUTH_FACEBOOK_NAME',
93 'OAUTH_FACEBOOK_ID',
94 'OAUTH_FACEBOOK_SECRET',
95 ),
96 array(
97 'OAUTH_FITBIT_NAME',
98 'OAUTH_FITBIT_ID',
99 'OAUTH_FITBIT_SECRET',
100 ),
101 array(
102 'OAUTH_FIVEHUNDREDPX_NAME',
103 'OAUTH_FIVEHUNDREDPX_ID',
104 'OAUTH_FIVEHUNDREDPX_SECRET',
105 ),
106 array(
107 'OAUTH_FLICKR_NAME',
108 'OAUTH_FLICKR_ID',
109 'OAUTH_FLICKR_SECRET',
110 ),
111 array(
112 'OAUTH_FOURSQUARE_NAME',
113 'OAUTH_FOURSQUARE_ID',
114 'OAUTH_FOURSQUARE_SECRET',
115 ),
116 array(
117 'OAUTH_GITHUB_NAME',
118 'OAUTH_GITHUB_ID',
119 'OAUTH_GITHUB_SECRET',
120 'OAUTH_GITHUB_DESC',
121 ),
122 array(
123 'OAUTH_GOOGLE_NAME',
124 'OAUTH_GOOGLE_ID',
125 'OAUTH_GOOGLE_SECRET',
126 'OAUTH_GOOGLE_DESC',
127 ),
128 array(
129 'OAUTH_HUBIC_NAME',
130 'OAUTH_HUBIC_ID',
131 'OAUTH_HUBIC_SECRET',
132 ),
133 array(
134 'OAUTH_INSTAGRAM_NAME',
135 'OAUTH_INSTAGRAM_ID',
136 'OAUTH_INSTAGRAM_SECRET',
137 ),
138 array(
139 'OAUTH_LINKEDIN_NAME',
140 'OAUTH_LINKEDIN_ID',
141 'OAUTH_LINKEDIN_SECRET',
142 ),
143 array(
144 'OAUTH_MAILCHIMP_NAME',
145 'OAUTH_MAILCHIMP_ID',
146 'OAUTH_MAILCHIMP_SECRET',
147 ),
148 array(
149 'OAUTH_MICROSOFT_NAME',
150 'OAUTH_MICROSOFT_ID',
151 'OAUTH_MICROSOFT_SECRET',
152 ),
153 array(
154 'OAUTH_MICROSOFT2_NAME',
155 'OAUTH_MICROSOFT2_ID',
156 'OAUTH_MICROSOFT2_SECRET',
157 ),
158 array(
159 'OAUTH_NEST_NAME',
160 'OAUTH_NEST_ID',
161 'OAUTH_NEST_SECRET',
162 ),
163 array(
164 'OAUTH_NETATMO_NAME',
165 'OAUTH_NETATMO_ID',
166 'OAUTH_NETATMO_SECRET',
167 ),
168 array(
169 'OAUTH_PARROTFLOWERPOWER_NAME',
170 'OAUTH_PARROTFLOWERPOWER_ID',
171 'OAUTH_PARROTFLOWERPOWER_SECRET',
172 ),
173 array(
174 'OAUTH_PAYPAL_NAME',
175 'OAUTH_PAYPAL_ID',
176 'OAUTH_PAYPAL_SECRET',
177 ),
178 array(
179 'OAUTH_POCKET_NAME',
180 'OAUTH_POCKET_ID',
181 'OAUTH_POCKET_SECRET',
182 ),
183 array(
184 'OAUTH_QUICKBOOKS_NAME',
185 'OAUTH_QUICKBOOKS_ID',
186 'OAUTH_QUICKBOOKS_SECRET',
187 ),
188 array(
189 'OAUTH_REDDIT_NAME',
190 'OAUTH_REDDIT_ID',
191 'OAUTH_REDDIT_SECRET',
192 ),
193 array(
194 'OAUTH_REDMINE_NAME',
195 'OAUTH_REDMINE_ID',
196 'OAUTH_REDMINE_SECRET',
197 ),
198 array(
199 'OAUTH_RUNKEEPER_NAME',
200 'OAUTH_RUNKEEPER_ID',
201 'OAUTH_RUNKEEPER_SECRET',
202 ),
203 array(
204 'OAUTH_SCOOPIT_NAME',
205 'OAUTH_SCOOPIT_ID',
206 'OAUTH_SCOOPIT_SECRET',
207 ),
208 array(
209 'OAUTH_SOUNDCLOUD_NAME',
210 'OAUTH_SOUNDCLOUD_ID',
211 'OAUTH_SOUNDCLOUD_SECRET',
212 ),
213 array(
214 'OAUTH_SPOTIFY_NAME',
215 'OAUTH_SPOTIFY_ID',
216 'OAUTH_SPOTIFY_SECRET',
217 ),
218 array(
219 'OAUTH_STRAVA_NAME',
220 'OAUTH_STRAVA_ID',
221 'OAUTH_STRAVA_SECRET',
222 ),
223 array(
224 'OAUTH_STRIPE_TEST_NAME',
225 'OAUTH_STRIPE_TEST_ID',
226 'STRIPE_TEST_SECRET_KEY',
227 ),
228 array(
229 'OAUTH_STRIPE_LIVE_NAME',
230 'OAUTH_STRIPE_LIVE_ID',
231 'STRIPE_LIVE_SECRET_KEY',
232 ),
233 array(
234 'OAUTH_TUMBLR_NAME',
235 'OAUTH_TUMBLR_ID',
236 'OAUTH_TUMBLR_SECRET',
237 ),
238 array(
239 'OAUTH_TWITTER_NAME',
240 'OAUTH_TWITTER_ID',
241 'OAUTH_TWITTER_SECRET',
242 ),
243 array(
244 'OAUTH_USTREAM_NAME',
245 'OAUTH_USTREAM_ID',
246 'OAUTH_USTREAM_SECRET',
247 ),
248 array(
249 'OAUTH_VIMEO_NAME',
250 'OAUTH_VIMEO_ID',
251 'OAUTH_VIMEO_SECRET',
252 ),
253 array(
254 'OAUTH_YAHOO_NAME',
255 'OAUTH_YAHOO_ID',
256 'OAUTH_YAHOO_SECRET',
257 ),
258 array(
259 'OAUTH_YAMMER_NAME',
260 'OAUTH_YAMMER_ID',
261 'OAUTH_YAMMER_SECRET',
262 ),
263 array(
264 'OAUTH_OTHER_NAME',
265 'OAUTH_OTHER_ID',
266 'OAUTH_OTHER_SECRET',
267 )
268 );
269
270 return $list;
271}
272
273
280{
281 // Supported OAUTH (a provider is supported when a file xxx_oauthcallback.php is available into htdocs/core/modules/oauth)
282 $supportedoauth2array = array(
283 'OAUTH_GOOGLE_NAME' => array(
284 'callbackfile' => 'google', // used to generate the filename: google_oauthcallback.php
285 'picto' => 'google',
286 'urlforapp' => 'OAUTH_GOOGLE_DESC',
287 'name' => 'Google',
288 'urlforcredentials' => 'https://console.developers.google.com/',
289 'availablescopes' => 'userinfo_email,userinfo_profile,openid,email,profile,cloud_print,admin_directory_user,gmail_full,contact,https://www.googleapis.com/auth/contacts,https://www.googleapis.com/auth/calendar',
290 'returnurl' => '/core/modules/oauth/google_oauthcallback.php'
291 ),
292 );
293 if (isModEnabled('stripe')) {
294 $supportedoauth2array['OAUTH_STRIPE_TEST_NAME'] = array(
295 'callbackfile' => 'stripetest',
296 'picto' => 'stripe',
297 'urlforapp' => '',
298 'name' => 'StripeTest',
299 'urlforcredentials' => 'https://dashboard.stripe.com/settings/connect',
300 'availablescopes' => 'read_write',
301 'returnurl' => '/core/modules/oauth/stripetest_oauthcallback.php'
302 );
303 $supportedoauth2array['OAUTH_STRIPE_LIVE_NAME'] = array(
304 'callbackfile' => 'stripelive',
305 'picto' => 'stripe',
306 'urlforapp' => '',
307 'name' => 'StripeLive',
308 'urlforcredentials' => 'https://dashboard.stripe.com/settings/connect',
309 'availablescopes' => 'read_write',
310 'returnurl' => '/core/modules/oauth/stripelive_oauthcallback.php'
311 );
312 }
313 $supportedoauth2array['OAUTH_GITHUB_NAME'] = array(
314 'callbackfile' => 'github',
315 'picto' => 'github',
316 'urlforapp' => 'OAUTH_GITHUB_DESC',
317 'name' => 'GitHub',
318 'urlforcredentials' => 'https://github.com/settings/developers',
319 'availablescopes' => 'user,public_repo',
320 'returnurl' => '/core/modules/oauth/github_oauthcallback.php'
321 );
322 // See https://learn.microsoft.com/fr-fr/azure/active-directory/develop/quickstart-register-app#register-an-application
323 $supportedoauth2array['OAUTH_MICROSOFT_NAME'] = array(
324 'callbackfile' => 'microsoft',
325 'picto' => 'microsoft',
326 'urlforapp' => 'OAUTH_MICROSOFT_DESC',
327 'name' => 'Microsoft [outlook.office365]',
328 'urlforcredentials' => 'https://portal.azure.com/',
329 // User.Read is a microsoftgraph scope, if it's not working, do not select it
330 'availablescopes' => 'openid,offline_access,profile,email,User.Read,https://outlook.office365.com/IMAP.AccessAsUser.All,https://outlook.office365.com/SMTP.Send',
331 'returnurl' => '/core/modules/oauth/microsoft_oauthcallback.php'
332 );
333 $supportedoauth2array['OAUTH_MICROSOFT2_NAME'] = array(
334 'callbackfile' => 'microsoft2',
335 'picto' => 'microsoft',
336 'urlforapp' => 'OAUTH_MICROSOFT2_DESC',
337 'name' => 'Microsoft [outlook.office]',
338 'urlforcredentials' => 'https://portal.azure.com/',
339 // User.Read is a microsoftgraph scope, if it's not working, do not select it
340 'availablescopes' => 'openid,offline_access,profile,email,User.Read,https://outlook.office.com/.default',
341 'returnurl' => '/core/modules/oauth/microsoft_oauthcallback.php'
342 );
343 if (getDolGlobalInt('MAIN_FEATURES_LEVEL') >= 2) {
344 $supportedoauth2array['OAUTH_OTHER_NAME'] = array(
345 'callbackfile' => 'generic',
346 'picto' => 'generic',
347 'urlforapp' => 'OAUTH_OTHER_DESC',
348 'name' => 'Other',
349 'urlforcredentials' => '',
350 'availablescopes' => 'Standard',
351 'returnurl' => '/core/modules/oauth/generic_oauthcallback.php'
352 );
353 }
354
355 return $supportedoauth2array;
356}
357
358
365{
366 global $langs, $conf;
367 $h = 0;
368 $head = array();
369
370 $head[$h][0] = dol_buildpath('/admin/oauth.php', 1);
371 $head[$h][1] = $langs->trans("OAuthServices");
372 $head[$h][2] = 'services';
373 $h++;
374
375 $head[$h][0] = dol_buildpath('/admin/oauthlogintokens.php', 1);
376 $head[$h][1] = $langs->trans("TokenManager");
377 $head[$h][2] = 'tokengeneration';
378 $h++;
379
380 complete_head_from_modules($conf, $langs, null, $head, $h, 'oauthadmin');
381
382 complete_head_from_modules($conf, $langs, null, $head, $h, 'oauthadmin', 'remove');
383
384
385 return $head;
386}
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
complete_head_from_modules($conf, $langs, $object, &$head, &$h, $type, $mode='add', $filterorigmodule='')
Complete or removed entries into a head array (used to build tabs).
getAllOauth2Array()
Return array of possible OAUTH2 services.
Definition oauth.lib.php:33
getSupportedOauth2Array()
Return array of tabs to used on pages to setup cron module.
oauthadmin_prepare_head()
Return array of tabs to used on pages to setup cron module.