This plugin provides templates, php classes, and other tools to support other CiviCRM plugins that connect to oauth based apis to sync users and groups.
By itself the plugin does not provide any user facing functionality.
This plugin is not complete - do not use it yet
The extension is licensed under AGPL-3.0.
- PHP v5.4+
- CiviCRM 5.4
This extension has not yet been published for installation via the web UI.
Sysadmins and developers may download the .zip
file for this extension and
install it with the command-line tool cv.
cd <extension-dir>
cv dl com.hjed.civicrm.oauth-sync@https://github.com/hjed/com.hjed.civicrm.oauth-sync/archive/master.zip
Sysadmins and developers may clone the Git repo for this extension and install it with the command-line tool cv.
git clone https://github.com/hjed/com.hjed.civicrm.oauth-sync.git
cv en oauth_sync
This plugin is provides an interface for other plugins. By itself it does nothing.
Below is the required information for plugins that use this plugin:
This plugin uses a prefix
for each connection it is managing (E.g. jira
, github
, facebook
). Connection plugins
should suply this.
The plugin expects certain settings to be defined for each connection, this can be done by getting your plugin to include
the value of CRM_OAuthSync_Settings::generateSettings
in your plugin's settings array. For the most part the plugin will then manage these seetings.
The plugin provides a number of template pages that can be used to manage connections:
The CRM_OauthSync_Form_ConnectionSettings
class provides a template for setting the client_id and client_secret for your oauth plugin.
Simply extend this class and implement the abstract methods.
If you do not implement this class you will need to set the (prefix)_client_id
and (prefix)_secret
settings, before
attempting an ouath connection.
The plugin provides a set of helper functions for Three Legged OAuth Consent. The following code snippet demonstrates their usage.
// get a new state key, including the settings prefix
$state = $oauthHelper->newStateKey();
// generate the redirect url
$redirect_url= CRM_OauthSync_OAuthHelper::generateRedirectUrlEncoded();
// use inbuilt page variables to get the path to the current page (assuming $this is a page)
CRM_JiraConnect_JiraApiHelper::oauthHelper()->setOauthCallbackReturnPath(
join('/', $this->urlPath)
);
// generate the url
$oauth_url = 'https://oauth_url.example.com/authorize?audience=api.atlassian.com&client_id=' . $client_id . '&scope=manage:jira-configuration%20offline_access&redirect_uri=' . $redirect_url . '&state=' . $state . '&response_type=code&prompt=consent'
($oauth_helper
is an instance of CRM_OauthSync_OAuthHelper
)
$oauth_url
then becomes a link you can provide to the user to go through the consent flow. The redirect will occur through
the plugin allowing it to complete the final step in the oauth flow and retrieve the token.
The plugin provides a number of additional CiviCRM hooks that can be used to manage your connection.
(This is inspired by nz.co.fuzion.accountsync)
Called on the successful completion of the consent flow. Plugins may want to handle this hook to provide functionality like selecting the correct site to sync with (if the api you are using supports multiple sites/accounts/installations/etc).
Called when the plugin needs the group list to be updated. Plugins should call the relevant api endpoint to update the groups list and add those groups to the array passed in.
Signature:
- &$groups : array - an array to fill with the list of remote groups
Called by the plugin when it needs to get the full list of users in a remote group. This will normally occur when a remote group is added to a normal group.
Signature:
- $remoteGroupName : string - the remote group we want to get the users for
- &$members : array(int) - a list of user ids for the remote group
Called by the plugin when users are removed or added to a local group. This should apply the update to the remote service.
Signature:
- $remoteGroupName : string - the remote group we are editing
- $toRemove : array(int) - a list of user ids to be removed
- $toAdd : array(int) = a list of user ids to be added
Plugins must define the following option groups.
Defines the available groups in the remote system that can be synced too.
The data_type
should be String
. E.g. if implemented in auto_install.xml
<OptionGroups>
<OptionGroup>
<name>my_prefix_sync_groups_options</name>
<title>My Connection Groups</title>
<data_type>String</data_type>
<is_reserved>1</is_reserved>
<is_active>1</is_active>
</OptionGroup>
</OptionGroups>
(* FIXME *)