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