dolibarr  17.0.4
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 // Supported OAUTH (a provider is supported when a file xxx_oauthcallback.php is available into htdocs/core/modules/oauth)
27 $supportedoauth2array = array(
28  'OAUTH_GOOGLE_NAME'=>array('callbackfile' => 'google', 'picto' => 'google', 'urlforapp' => 'OAUTH_GOOGLE_DESC', 'name'=>'Google', 'urlforcredentials'=>'https://console.developers.google.com/',
29  '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', 'returnurl'=>'/core/modules/oauth/google_oauthcallback.php'),
30 );
31 if (isModEnabled('stripe')) {
32  $supportedoauth2array['OAUTH_STRIPE_TEST_NAME'] = array('callbackfile' => 'stripetest', 'picto' => 'stripe', 'urlforapp' => '', 'name'=>'StripeTest', 'urlforcredentials'=>'', 'availablescopes'=>'read_write', 'returnurl'=>'/core/modules/oauth/stripetest_oauthcallback.php');
33  $supportedoauth2array['OAUTH_STRIPE_LIVE_NAME'] = array('callbackfile' => 'stripelive', 'picto' => 'stripe', 'urlforapp' => '', 'name'=>'StripeLive', 'urlforcredentials'=>'', 'availablescopes'=>'read_write', 'returnurl'=>'/core/modules/oauth/stripelive_oauthcallback.php');
34 }
35 $supportedoauth2array['OAUTH_GITHUB_NAME'] = array('callbackfile' => 'github', 'picto' => 'github', 'urlforapp' => 'OAUTH_GITHUB_DESC', 'name'=>'GitHub', 'urlforcredentials'=>'https://github.com/settings/developers', 'availablescopes'=>'user,public_repo', 'returnurl'=>'/core/modules/oauth/github_oauthcallback.php');
36 $supportedoauth2array['OAUTH_MICROSOFT_NAME'] = array('callbackfile' => 'microsoft', 'picto' => 'microsoft', 'urlforapp' => 'OAUTH_MICROSOFT_DESC', 'name'=>'Microsoft', 'urlforcredentials'=>'https://portal.azure.com/', 'availablescopes'=>'openid,offline_access,profile,email,User.Read,https://outlook.office365.com/IMAP.AccessAsUser.All,https://outlook.office365.com/SMTP.Send', 'returnurl'=>'/core/modules/oauth/microsoft_oauthcallback.php');
37 if (getDolGlobalInt('MAIN_FEATURES_LEVEL') >= 2) {
38  $supportedoauth2array['OAUTH_OTHER_NAME'] = array('callbackfile' => 'generic', 'picto' => 'generic', 'urlforapp' => 'OAUTH_OTHER_DESC', 'name'=>'Other', 'urlforcredentials'=>'', 'availablescopes'=>'Standard', 'returnurl'=>'/core/modules/oauth/generic_oauthcallback.php');
39  // See https://learn.microsoft.com/fr-fr/azure/active-directory/develop/quickstart-register-app#register-an-application
40 }
41 
42 
43 // API access parameters OAUTH
44 $list = array(
45  array(
46  'OAUTH_AMAZON_NAME',
47  'OAUTH_AMAZON_ID',
48  'OAUTH_AMAZON_SECRET',
49  ),
50  array(
51  'OAUTH_BITBUCKET_NAME',
52  'OAUTH_BITBUCKET_ID',
53  'OAUTH_BITBUCKET_SECRET',
54  ),
55  array(
56  'OAUTH_BITLY_NAME',
57  'OAUTH_BITLY_ID',
58  'OAUTH_BITLY_SECRET',
59  ),
60  array(
61  'OAUTH_BITRIX24_NAME',
62  'OAUTH_BITRIX24_ID',
63  'OAUTH_BITRIX24_SECRET',
64  ),
65  array(
66  'OAUTH_BOX_NAME',
67  'OAUTH_BOX_ID',
68  'OAUTH_BOX_SECRET',
69  ),
70  array(
71  'OAUTH_BUFFER_NAME',
72  'OAUTH_BUFFER_ID',
73  'OAUTH_BUFFER_SECRET',
74  ),
75  array(
76  'OAUTH_DAILYMOTION_NAME',
77  'OAUTH_DAILYMOTION_ID',
78  'OAUTH_DAILYMOTION_SECRET',
79  ),
80  array(
81  'OAUTH_DEVIANTART_NAME',
82  'OAUTH_DEVIANTART_ID',
83  'OAUTH_DEVIANTART_SECRET',
84  ),
85  array(
86  'OAUTH_DROPBOX_NAME',
87  'OAUTH_DROPBOX_ID',
88  'OAUTH_DROPBOX_SECRET',
89  ),
90  array(
91  'OAUTH_ETSY_NAME',
92  'OAUTH_ETSY_ID',
93  'OAUTH_ETSY_SECRET',
94  ),
95  array(
96  'OAUTH_EVEONLINE_NAME',
97  'OAUTH_EVEONLINE_ID',
98  'OAUTH_EVEONLINE_SECRET',
99  ),
100  array(
101  'OAUTH_FACEBOOK_NAME',
102  'OAUTH_FACEBOOK_ID',
103  'OAUTH_FACEBOOK_SECRET',
104  ),
105  array(
106  'OAUTH_FITBIT_NAME',
107  'OAUTH_FITBIT_ID',
108  'OAUTH_FITBIT_SECRET',
109  ),
110  array(
111  'OAUTH_FIVEHUNDREDPX_NAME',
112  'OAUTH_FIVEHUNDREDPX_ID',
113  'OAUTH_FIVEHUNDREDPX_SECRET',
114  ),
115  array(
116  'OAUTH_FLICKR_NAME',
117  'OAUTH_FLICKR_ID',
118  'OAUTH_FLICKR_SECRET',
119  ),
120  array(
121  'OAUTH_FOURSQUARE_NAME',
122  'OAUTH_FOURSQUARE_ID',
123  'OAUTH_FOURSQUARE_SECRET',
124  ),
125  array(
126  'OAUTH_GITHUB_NAME',
127  'OAUTH_GITHUB_ID',
128  'OAUTH_GITHUB_SECRET',
129  'OAUTH_GITHUB_DESC',
130  ),
131  array(
132  'OAUTH_GOOGLE_NAME',
133  'OAUTH_GOOGLE_ID',
134  'OAUTH_GOOGLE_SECRET',
135  'OAUTH_GOOGLE_DESC',
136  ),
137  array(
138  'OAUTH_HUBIC_NAME',
139  'OAUTH_HUBIC_ID',
140  'OAUTH_HUBIC_SECRET',
141  ),
142  array(
143  'OAUTH_INSTAGRAM_NAME',
144  'OAUTH_INSTAGRAM_ID',
145  'OAUTH_INSTAGRAM_SECRET',
146  ),
147  array(
148  'OAUTH_LINKEDIN_NAME',
149  'OAUTH_LINKEDIN_ID',
150  'OAUTH_LINKEDIN_SECRET',
151  ),
152  array(
153  'OAUTH_MAILCHIMP_NAME',
154  'OAUTH_MAILCHIMP_ID',
155  'OAUTH_MAILCHIMP_SECRET',
156  ),
157  array(
158  'OAUTH_MICROSOFT_NAME',
159  'OAUTH_MICROSOFT_ID',
160  'OAUTH_MICROSOFT_SECRET',
161  ),
162  array(
163  'OAUTH_NEST_NAME',
164  'OAUTH_NEST_ID',
165  'OAUTH_NEST_SECRET',
166  ),
167  array(
168  'OAUTH_NETATMO_NAME',
169  'OAUTH_NETATMO_ID',
170  'OAUTH_NETATMO_SECRET',
171  ),
172  array(
173  'OAUTH_PARROTFLOWERPOWER_NAME',
174  'OAUTH_PARROTFLOWERPOWER_ID',
175  'OAUTH_PARROTFLOWERPOWER_SECRET',
176  ),
177  array(
178  'OAUTH_PAYPAL_NAME',
179  'OAUTH_PAYPAL_ID',
180  'OAUTH_PAYPAL_SECRET',
181  ),
182  array(
183  'OAUTH_POCKET_NAME',
184  'OAUTH_POCKET_ID',
185  'OAUTH_POCKET_SECRET',
186  ),
187  array(
188  'OAUTH_QUICKBOOKS_NAME',
189  'OAUTH_QUICKBOOKS_ID',
190  'OAUTH_QUICKBOOKS_SECRET',
191  ),
192  array(
193  'OAUTH_REDDIT_NAME',
194  'OAUTH_REDDIT_ID',
195  'OAUTH_REDDIT_SECRET',
196  ),
197  array(
198  'OAUTH_REDMINE_NAME',
199  'OAUTH_REDMINE_ID',
200  'OAUTH_REDMINE_SECRET',
201  ),
202  array(
203  'OAUTH_RUNKEEPER_NAME',
204  'OAUTH_RUNKEEPER_ID',
205  'OAUTH_RUNKEEPER_SECRET',
206  ),
207  array(
208  'OAUTH_SCOOPIT_NAME',
209  'OAUTH_SCOOPIT_ID',
210  'OAUTH_SCOOPIT_SECRET',
211  ),
212  array(
213  'OAUTH_SOUNDCLOUD_NAME',
214  'OAUTH_SOUNDCLOUD_ID',
215  'OAUTH_SOUNDCLOUD_SECRET',
216  ),
217  array(
218  'OAUTH_SPOTIFY_NAME',
219  'OAUTH_SPOTIFY_ID',
220  'OAUTH_SPOTIFY_SECRET',
221  ),
222  array(
223  'OAUTH_STRAVA_NAME',
224  'OAUTH_STRAVA_ID',
225  'OAUTH_STRAVA_SECRET',
226  ),
227  array(
228  'OAUTH_STRIPE_TEST_NAME',
229  'OAUTH_STRIPE_TEST_ID',
230  'STRIPE_TEST_SECRET_KEY',
231  ),
232  array(
233  'OAUTH_STRIPE_LIVE_NAME',
234  'OAUTH_STRIPE_LIVE_ID',
235  'STRIPE_LIVE_SECRET_KEY',
236  ),
237  array(
238  'OAUTH_TUMBLR_NAME',
239  'OAUTH_TUMBLR_ID',
240  'OAUTH_TUMBLR_SECRET',
241  ),
242  array(
243  'OAUTH_TWITTER_NAME',
244  'OAUTH_TWITTER_ID',
245  'OAUTH_TWITTER_SECRET',
246  ),
247  array(
248  'OAUTH_USTREAM_NAME',
249  'OAUTH_USTREAM_ID',
250  'OAUTH_USTREAM_SECRET',
251  ),
252  array(
253  'OAUTH_VIMEO_NAME',
254  'OAUTH_VIMEO_ID',
255  'OAUTH_VIMEO_SECRET',
256  ),
257  array(
258  'OAUTH_YAHOO_NAME',
259  'OAUTH_YAHOO_ID',
260  'OAUTH_YAHOO_SECRET',
261  ),
262  array(
263  'OAUTH_YAMMER_NAME',
264  'OAUTH_YAMMER_ID',
265  'OAUTH_YAMMER_SECRET',
266  ),
267  array(
268  'OAUTH_OTHER_NAME',
269  'OAUTH_OTHER_ID',
270  'OAUTH_OTHER_SECRET',
271  ),
272 );
273 
274 
275 
282 {
283  global $langs, $conf;
284  $h = 0;
285  $head = array();
286 
287  $head[$h][0] = dol_buildpath('/admin/oauth.php', 1);
288  $head[$h][1] = $langs->trans("OAuthServices");
289  $head[$h][2] = 'services';
290  $h++;
291 
292  $head[$h][0] = dol_buildpath('/admin/oauthlogintokens.php', 1);
293  $head[$h][1] = $langs->trans("TokenManager");
294  $head[$h][2] = 'tokengeneration';
295  $h++;
296 
297  complete_head_from_modules($conf, $langs, null, $head, $h, 'oauthadmin');
298 
299  complete_head_from_modules($conf, $langs, null, $head, $h, 'oauthadmin', 'remove');
300 
301 
302  return $head;
303 }
getDolGlobalInt($key, $default=0)
Return 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).
isModEnabled($module)
Is Dolibarr module enabled.
oauthadmin_prepare_head()
Return array of tabs to used on pages to setup cron module.
Definition: oauth.lib.php:281