dolibarr 19.0.3
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_NEST_NAME',
155 'OAUTH_NEST_ID',
156 'OAUTH_NEST_SECRET',
157 ),
158 array(
159 'OAUTH_NETATMO_NAME',
160 'OAUTH_NETATMO_ID',
161 'OAUTH_NETATMO_SECRET',
162 ),
163 array(
164 'OAUTH_PARROTFLOWERPOWER_NAME',
165 'OAUTH_PARROTFLOWERPOWER_ID',
166 'OAUTH_PARROTFLOWERPOWER_SECRET',
167 ),
168 array(
169 'OAUTH_PAYPAL_NAME',
170 'OAUTH_PAYPAL_ID',
171 'OAUTH_PAYPAL_SECRET',
172 ),
173 array(
174 'OAUTH_POCKET_NAME',
175 'OAUTH_POCKET_ID',
176 'OAUTH_POCKET_SECRET',
177 ),
178 array(
179 'OAUTH_QUICKBOOKS_NAME',
180 'OAUTH_QUICKBOOKS_ID',
181 'OAUTH_QUICKBOOKS_SECRET',
182 ),
183 array(
184 'OAUTH_REDDIT_NAME',
185 'OAUTH_REDDIT_ID',
186 'OAUTH_REDDIT_SECRET',
187 ),
188 array(
189 'OAUTH_REDMINE_NAME',
190 'OAUTH_REDMINE_ID',
191 'OAUTH_REDMINE_SECRET',
192 ),
193 array(
194 'OAUTH_RUNKEEPER_NAME',
195 'OAUTH_RUNKEEPER_ID',
196 'OAUTH_RUNKEEPER_SECRET',
197 ),
198 array(
199 'OAUTH_SCOOPIT_NAME',
200 'OAUTH_SCOOPIT_ID',
201 'OAUTH_SCOOPIT_SECRET',
202 ),
203 array(
204 'OAUTH_SOUNDCLOUD_NAME',
205 'OAUTH_SOUNDCLOUD_ID',
206 'OAUTH_SOUNDCLOUD_SECRET',
207 ),
208 array(
209 'OAUTH_SPOTIFY_NAME',
210 'OAUTH_SPOTIFY_ID',
211 'OAUTH_SPOTIFY_SECRET',
212 ),
213 array(
214 'OAUTH_STRAVA_NAME',
215 'OAUTH_STRAVA_ID',
216 'OAUTH_STRAVA_SECRET',
217 ),
218 array(
219 'OAUTH_STRIPE_TEST_NAME',
220 'OAUTH_STRIPE_TEST_ID',
221 'STRIPE_TEST_SECRET_KEY',
222 ),
223 array(
224 'OAUTH_STRIPE_LIVE_NAME',
225 'OAUTH_STRIPE_LIVE_ID',
226 'STRIPE_LIVE_SECRET_KEY',
227 ),
228 array(
229 'OAUTH_TUMBLR_NAME',
230 'OAUTH_TUMBLR_ID',
231 'OAUTH_TUMBLR_SECRET',
232 ),
233 array(
234 'OAUTH_TWITTER_NAME',
235 'OAUTH_TWITTER_ID',
236 'OAUTH_TWITTER_SECRET',
237 ),
238 array(
239 'OAUTH_USTREAM_NAME',
240 'OAUTH_USTREAM_ID',
241 'OAUTH_USTREAM_SECRET',
242 ),
243 array(
244 'OAUTH_VIMEO_NAME',
245 'OAUTH_VIMEO_ID',
246 'OAUTH_VIMEO_SECRET',
247 ),
248 array(
249 'OAUTH_YAHOO_NAME',
250 'OAUTH_YAHOO_ID',
251 'OAUTH_YAHOO_SECRET',
252 ),
253 array(
254 'OAUTH_YAMMER_NAME',
255 'OAUTH_YAMMER_ID',
256 'OAUTH_YAMMER_SECRET',
257 ),
258 array(
259 'OAUTH_OTHER_NAME',
260 'OAUTH_OTHER_ID',
261 'OAUTH_OTHER_SECRET',
262 )
263 );
264
265 return $list;
266}
267
268
275{
276 // Supported OAUTH (a provider is supported when a file xxx_oauthcallback.php is available into htdocs/core/modules/oauth)
277 $supportedoauth2array = array(
278 'OAUTH_GOOGLE_NAME' => array(
279 'callbackfile' => 'google',
280 'picto' => 'google',
281 'urlforapp' => 'OAUTH_GOOGLE_DESC',
282 'name' => 'Google',
283 'urlforcredentials' => 'https://console.developers.google.com/',
284 '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',
285 'returnurl' => '/core/modules/oauth/google_oauthcallback.php'
286 ),
287 );
288 if (isModEnabled('stripe')) {
289 $supportedoauth2array['OAUTH_STRIPE_TEST_NAME'] = array(
290 'callbackfile' => 'stripetest',
291 'picto' => 'stripe',
292 'urlforapp' => '',
293 'name' => 'StripeTest',
294 'urlforcredentials' => 'https://dashboard.stripe.com/settings/connect',
295 'availablescopes' => 'read_write',
296 'returnurl' => '/core/modules/oauth/stripetest_oauthcallback.php'
297 );
298 $supportedoauth2array['OAUTH_STRIPE_LIVE_NAME'] = array(
299 'callbackfile' => 'stripelive',
300 'picto' => 'stripe',
301 'urlforapp' => '',
302 'name' => 'StripeLive',
303 'urlforcredentials' => 'https://dashboard.stripe.com/settings/connect',
304 'availablescopes' => 'read_write',
305 'returnurl' => '/core/modules/oauth/stripelive_oauthcallback.php'
306 );
307 }
308 $supportedoauth2array['OAUTH_GITHUB_NAME'] = array(
309 'callbackfile' => 'github',
310 'picto' => 'github',
311 'urlforapp' => 'OAUTH_GITHUB_DESC',
312 'name' => 'GitHub',
313 'urlforcredentials' => 'https://github.com/settings/developers',
314 'availablescopes' => 'user,public_repo',
315 'returnurl' => '/core/modules/oauth/github_oauthcallback.php'
316 );
317 // See https://learn.microsoft.com/fr-fr/azure/active-directory/develop/quickstart-register-app#register-an-application
318 $supportedoauth2array['OAUTH_MICROSOFT_NAME'] = array(
319 'callbackfile' => 'microsoft',
320 'picto' => 'microsoft',
321 'urlforapp' => 'OAUTH_MICROSOFT_DESC',
322 'name' => 'Microsoft',
323 'urlforcredentials' => 'https://portal.azure.com/',
324 // User.Read is a microsoftgraph scope, if it's not working, do not select it
325 'availablescopes' => 'openid,offline_access,profile,email,User.Read,https://outlook.office365.com/IMAP.AccessAsUser.All,https://outlook.office365.com/SMTP.Send',
326 'returnurl' => '/core/modules/oauth/microsoft_oauthcallback.php'
327 );
328 if (getDolGlobalInt('MAIN_FEATURES_LEVEL') >= 2) {
329 $supportedoauth2array['OAUTH_OTHER_NAME'] = array(
330 'callbackfile' => 'generic',
331 'picto' => 'generic',
332 'urlforapp' => 'OAUTH_OTHER_DESC',
333 'name' => 'Other',
334 'urlforcredentials' => '',
335 'availablescopes' => 'Standard',
336 'returnurl' => '/core/modules/oauth/generic_oauthcallback.php'
337 );
338 }
339
340 return $supportedoauth2array;
341}
342
343
350{
351 global $langs, $conf;
352 $h = 0;
353 $head = array();
354
355 $head[$h][0] = dol_buildpath('/admin/oauth.php', 1);
356 $head[$h][1] = $langs->trans("OAuthServices");
357 $head[$h][2] = 'services';
358 $h++;
359
360 $head[$h][0] = dol_buildpath('/admin/oauthlogintokens.php', 1);
361 $head[$h][1] = $langs->trans("TokenManager");
362 $head[$h][2] = 'tokengeneration';
363 $h++;
364
365 complete_head_from_modules($conf, $langs, null, $head, $h, 'oauthadmin');
366
367 complete_head_from_modules($conf, $langs, null, $head, $h, 'oauthadmin', 'remove');
368
369
370 return $head;
371}
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.