oauth.lib.php 8.4 KB

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