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