Merge pull request #23762 from civicrm/5.51
[civicrm-core.git] / ext / oauth-client / oauth_client.php
CommitLineData
ed463944
TO
1<?php
2
3require_once 'oauth_client.civix.php';
4// phpcs:disable
5use CRM_OauthClient_ExtensionUtil as E;
6// phpcs:enable
7
8/**
9 * Implements hook_civicrm_config().
10 *
11 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_config/
12 */
13function oauth_client_civicrm_config(&$config) {
14 _oauth_client_civix_civicrm_config($config);
15}
ed463944 16
9959dad1
TO
17/**
18 * Implements hook_civicrm_permission().
19 *
20 * @see CRM_Utils_Hook::permission()
21 * @see CRM_Core_Permission::getCorePermissions()
22 */
23function oauth_client_civicrm_permission(&$permissions) {
24 $prefix = ts('CiviCRM') . ': ';
25 $permissions['manage OAuth client'] = [
26 $prefix . ts('manage OAuth client'),
27 ts('Create and delete OAuth client connections'),
28 ];
29 $permissions['manage OAuth client secrets'] = [
30 $prefix . ts('manage OAuth client secrets'),
31 ts('Access OAuth secrets'),
32 ];
d55f710f
NM
33 $permissions['create OAuth tokens via auth code flow'] = [
34 $prefix . ts('create OAuth tokens via auth code flow'),
35 ts('Create OAuth tokens via the authorization code flow'),
36 ];
37 $permissions['manage my OAuth contact tokens'] = [
38 $prefix . ts('manage my OAuth contact tokens'),
39 ts("Manage user's own OAuth tokens"),
40 ];
41 $permissions['manage all OAuth contact tokens'] = [
42 $prefix . ts('manage all OAuth contact tokens'),
43 ts("Manage OAuth tokens for all contacts"),
44 ];
9959dad1
TO
45}
46
ed463944
TO
47/**
48 * Implements hook_civicrm_entityTypes().
49 *
50 * Declare entity types provided by this module.
51 *
52 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_entityTypes
53 */
54function oauth_client_civicrm_entityTypes(&$entityTypes) {
55 _oauth_client_civix_civicrm_entityTypes($entityTypes);
56}
57
ed463944
TO
58// --- Functions below this ship commented out. Uncomment as required. ---
59
60/**
61 * Implements hook_civicrm_preProcess().
62 *
63 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_preProcess
64 */
65//function oauth_client_civicrm_preProcess($formName, &$form) {
66//
67//}
68
69/**
70 * Implements hook_civicrm_navigationMenu().
71 *
72 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_navigationMenu
73 */
74//function oauth_client_civicrm_navigationMenu(&$menu) {
75// _oauth_client_civix_insert_navigation_menu($menu, 'Mailings', array(
76// 'label' => E::ts('New subliminal message'),
77// 'name' => 'mailing_subliminal_message',
78// 'url' => 'civicrm/mailing/subliminal',
79// 'permission' => 'access CiviMail',
80// 'operator' => 'OR',
81// 'separator' => 0,
82// ));
83// _oauth_client_civix_navigationMenu($menu);
84//}
3ee128fb 85
a17b2d8a
TO
86/**
87 * @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
88 */
89function oauth_client_civicrm_container($container) {
90 $container->addResource(new \Symfony\Component\Config\Resource\FileResource(__FILE__));
91 $container->setDefinition('oauth2.league', new \Symfony\Component\DependencyInjection\Definition(
92 \Civi\OAuth\OAuthLeagueFacade::class, []))->setPublic(TRUE);
93 $container->setDefinition('oauth2.token', new \Symfony\Component\DependencyInjection\Definition(
94 \Civi\OAuth\OAuthTokenFacade::class, []))->setPublic(TRUE);
95}
96
3ee128fb
TO
97/**
98 * Implements hook_civicrm_oauthProviders().
99 */
100function oauth_client_civicrm_oauthProviders(&$providers) {
2752428e
TO
101 $ingest = function($pat) use (&$providers) {
102 $files = (array) glob($pat);
103 foreach ($files as $file) {
104 if (!defined('CIVICRM_TEST') && preg_match(';\.test\.json$;', $file)) {
105 continue;
106 }
107 $name = preg_replace(';\.(dist\.|test\.|)json$;', '', basename($file));
108 $provider = json_decode(file_get_contents($file), 1);
109 $provider['name'] = $name;
110 $providers[$name] = $provider;
3ee128fb
TO
111 }
112 };
113
2752428e
TO
114 $ingest(__DIR__ . '/providers/*.json');
115 $localDir = Civi::paths()->getPath('[civicrm.private]/oauth-providers');
116 if (file_exists($localDir)) {
117 $ingest($localDir . '/*.json');
3ee128fb
TO
118 }
119}
7be4bff1
TO
120
121/**
122 * Implements hook_civicrm_mailSetupActions().
123 *
124 * @see CRM_Utils_Hook::mailSetupActions()
125 */
126function oauth_client_civicrm_mailSetupActions(&$setupActions) {
127 $setupActions = array_merge($setupActions, CRM_OAuth_MailSetup::buildSetupLinks());
128}
129
130/**
131 * Implements hook_civicrm_oauthReturn().
132 */
133function oauth_client_civicrm_oauthReturn($token, &$nextUrl) {
134 CRM_OAuth_MailSetup::onReturn($token, $nextUrl);
135}
7dfe9078
TO
136
137/**
138 * Implements hook_civicrm_alterMailStore().
139 *
140 * @see CRM_Utils_Hook::alterMailStore()
141 */
142function oauth_client_civicrm_alterMailStore(&$mailSettings) {
143 CRM_OAuth_MailSetup::alterMailStore($mailSettings);
144}