*/
public static function get($checkPermissions = TRUE) {
$action = new Generic\BasicGetAction('OAuthProvider', __FUNCTION__, function () {
- $cache = \Civi::cache('short');
+ $cache = \Civi::cache('long');
if (!$cache->has('OAuthProvider_list')) {
$providers = [];
$event = GenericHookEvent::create([
+++ /dev/null
-[
- {
- "name": "ms-exchange",
- "title": "Microsoft: Exchange Online",
- "options": {
- "urlAuthorize": "https://login.microsoftonline.com/common/oauth2/v2.0/authorize",
- "urlAccessToken": "https://login.microsoftonline.com/common/oauth2/v2.0/token",
- "urlResourceOwnerDetails": "https://graph.microsoft.com/v1.0/me",
- "scopeSeparator": " ",
- "scopes": [
- "User.Read",
- "https://outlook.office.com/IMAP.AccessAsUser.All",
- "https://outlook.office.com/POP.AccessAsUser.All",
- "https://outlook.office.com/SMTP.Send",
- "offline_access"
- ]
- },
- "mailSettingsTemplate": {
- "name": "{{provider.name}}: {{token.resource_owner.mail}}",
- "domain": "{{token.resource_owner.mail|getMailDomain}}",
- "localpart": null,
- "return_path": null,
- "protocol:name": "IMAP",
- "server": "outlook.office365.com",
- "username": "{{token.resource_owner.mail}}",
- "password": null,
- "is_ssl": true
- }
- }
-]
+++ /dev/null
-[
- {
- "name": "test_example_1",
- "title": "First Test Example",
- "options": {
- "urlAuthorize": "https://example.com/one/auth",
- "urlAccessToken": "https://example.com/one/token",
- "urlResourceOwnerDetails": "https://example.com/one/owner",
- "scopes": ["scope-1-foo", "scope-1-bar"]
- }
- },
- {
- "name": "test_example_2",
- "title": "Second Test Example",
- "class": "My\\Example2",
- "options": {
- "urlAuthorize": "https://example.com/two",
- "scopes": ["scope-2-foo", "scope-2-bar"]
- }
- }
-]
* Implements hook_civicrm_oauthProviders().
*/
function oauth_client_civicrm_oauthProviders(&$providers) {
- $ingest = function($file) use (&$providers) {
- $parsed = json_decode(file_get_contents($file), 1);
- foreach ($parsed as $provider) {
- $providers[$provider['name']] = $provider;
+ $ingest = function($pat) use (&$providers) {
+ $files = (array) glob($pat);
+ foreach ($files as $file) {
+ if (!defined('CIVICRM_TEST') && preg_match(';\.test\.json$;', $file)) {
+ continue;
+ }
+ $name = preg_replace(';\.(dist\.|test\.|)json$;', '', basename($file));
+ $provider = json_decode(file_get_contents($file), 1);
+ $provider['name'] = $name;
+ $providers[$name] = $provider;
}
};
- $ingest(__DIR__ . '/data/oauth-providers.dist.json');
- if (defined('CIVICRM_TEST')) {
- $ingest(__DIR__ . '/data/oauth-providers.test.json');
- }
- $localFile = Civi::paths()->getPath('[civicrm.private]/oauth-providers.local.json');
- if (file_exists($localFile)) {
- $ingest($localFile);
+ $ingest(__DIR__ . '/providers/*.json');
+ $localDir = Civi::paths()->getPath('[civicrm.private]/oauth-providers');
+ if (file_exists($localDir)) {
+ $ingest($localDir . '/*.json');
}
}
--- /dev/null
+{
+ "title": "Google Mail",
+ "class": "League\\OAuth2\\Client\\Provider\\Google",
+ "options": {
+ "urlAuthorize": "https://accounts.google.com/o/oauth2/v2/auth",
+ "urlAccessToken": "https://www.googleapis.com/oauth2/v4/token",
+ "urlResourceOwnerDetails": "https://openidconnect.googleapis.com/v1/userinfo",
+ "accessType": "offline",
+ "scopeSeparator": " ",
+ "scopes": [
+ "https://mail.google.com/",
+ "openid"
+ ]
+ },
+ "mailSettingsTemplate": {
+ "name": "{{token.resource_owner.email}}",
+ "domain": "{{token.resource_owner.email|getMailDomain}}",
+ "localpart": null,
+ "return_path": null,
+ "protocol:name": "IMAP",
+ "server": "imap.gmail.com",
+ "username": "{{token.resource_owner.email}}",
+ "password": null,
+ "is_ssl": true
+ }
+}
\ No newline at end of file
--- /dev/null
+{
+ "title": "Microsoft Exchange Online",
+ "options": {
+ "urlAuthorize": "https://login.microsoftonline.com/common/oauth2/v2.0/authorize",
+ "urlAccessToken": "https://login.microsoftonline.com/common/oauth2/v2.0/token",
+ "urlResourceOwnerDetails": "https://graph.microsoft.com/v1.0/me",
+ "scopeSeparator": " ",
+ "scopes": [
+ "User.Read",
+ "https://outlook.office.com/IMAP.AccessAsUser.All",
+ "https://outlook.office.com/POP.AccessAsUser.All",
+ "https://outlook.office.com/SMTP.Send",
+ "offline_access"
+ ]
+ },
+ "mailSettingsTemplate": {
+ "name": "{{token.resource_owner.mail}}",
+ "domain": "{{token.resource_owner.mail|getMailDomain}}",
+ "localpart": null,
+ "return_path": null,
+ "protocol:name": "IMAP",
+ "server": "outlook.office365.com",
+ "username": "{{token.resource_owner.mail}}",
+ "password": null,
+ "is_ssl": true
+ }
+}
--- /dev/null
+{
+ "title": "First Test Example",
+ "options": {
+ "urlAuthorize": "https://example.com/one/auth",
+ "urlAccessToken": "https://example.com/one/token",
+ "urlResourceOwnerDetails": "https://example.com/one/owner",
+ "scopes": ["scope-1-foo", "scope-1-bar"]
+ }
+}
--- /dev/null
+{
+ "name": "test_example_2",
+ "title": "Second Test Example",
+ "class": "My\\Example2",
+ "options": {
+ "urlAuthorize": "https://example.com/two",
+ "scopes": ["scope-2-foo", "scope-2-bar"]
+ }
+}