The AuthManager is a CakePHP plugin which can be used for handling authentication such as OAUTH2. Compatible with PHP 5.4+.
Currently supported authentication methods:
- OAUTH2
Supported media platforms:
- Google Analytics
- Facebook Ads
- Bitly
- Google Tag Manager
- Google Search Console
- Bing Ads
- DoubleClick DCM/DFA Reporting and Trafficking API and DoubleClick Bid Manager API
- Coosto
- Dropbox
- Google AdWords
- LinkedIn Company Pages
- Twitter Ads
- Salesforce
To add an user you should POST to /AuthManager/MediaPlatformUser/addUser
with:
[
'MediaPlatform' => [
'id' => <MEDIA_PLATFORM_ID>
]
]
Where <MEDIA_PLATFORM_ID>
is a MediaPlatform ID that is implemented by the AuthManager. This page will redirect the user to an OAUTH page of the media platform asking for permission. The callback URL is automatically set, which is AuthManager/MediaPlatformUser/callback/<MEDIA_PLATFORM_ID>
.
Once an user has been added, you can get it's credentials through the AuthContainerFactory
. You get an AuthContainer by doing the following:
$authContainerFactory = new AuthContainerFactory();
// Where 1 is the MediaPlatformUser ID.
$authContainerFactory->createAuthContainer(1);
// If MediaPlatformUser ID #1 is a Facebook Ads account, it would return;
//> FacebookAdsAuthContainer
The AuthContainer contains different attributes depending on the media platform. For example FacebookAdsAuthContainer
contains;
Facebook $facebookSdk
\FacebookAds\Api $facebookAds
With these objects, which are Facebook's API objects, you can execute any API calls as the authenticated user.
- Copy the Lib/ExampleMediaPlatform folder.
- Rename the folder, files and classes to the name of your new Media Platform.
- Add a constant to the MediaPlatform model and also to the media_platforms table.
- Also add an authentication type if necessary.
- Implement the methods that are defined, all methods currently throw an exception.
- Add the Media Platform to the types array in Lib/MediaPlatformAuthManagerFactory.