-
Notifications
You must be signed in to change notification settings - Fork 39
Added getting started and authentication page #224
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 5.x
Are you sure you want to change the base?
Changes from 2 commits
e161ab7
c38b66b
dbb11a1
af4c574
4e0def7
08ce05a
d73847c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| from . import link | ||
|
|
||
| link_name = "Symfony Cache Documentation" | ||
| link_text = "Symfony Cache Documentation" | ||
| link_url = "https://symfony.com/doc/5.4/cache.html#configuring-cache-with-frameworkbundle" | ||
|
|
||
| link.xref_links.update({link_name: (link_text, link_url)}) |
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,301 @@ | ||||||||||
| Authentication | ||||||||||
| ############## | ||||||||||
|
|
||||||||||
| Mautic supports OAuth2 or Basic Authentication for API authentication. | ||||||||||
|
|
||||||||||
| Basic authentication | ||||||||||
| ******************** | ||||||||||
|
|
||||||||||
| To get started quickly with Mautic's API, you can use Basic Authentication. | ||||||||||
|
|
||||||||||
| .. note:: | ||||||||||
|
|
||||||||||
| Mautic recommends OAuth2 for security reasons. If you still want to use Basic Authentication, you must first enable it in ``Configuration -> API Settings`` in the Mautic UI, or by setting ``'api_enable_basic_auth' => true`` in ``app/config/local.php`` directly. | ||||||||||
|
|
||||||||||
| After enabling Basic Authentication, you can use it in Mautic's API as follows: | ||||||||||
|
|
||||||||||
| Using Mautic's API library with ``BasicAuth`` | ||||||||||
| ============================================= | ||||||||||
|
|
||||||||||
| .. code-block:: php | ||||||||||
|
|
||||||||||
| <?php | ||||||||||
|
|
||||||||||
| use GuzzleHttp\Client; | ||||||||||
| use Mautic\Auth\ApiAuth; | ||||||||||
| use Mautic\MauticApi; | ||||||||||
|
|
||||||||||
| // Initiate an HTTP Client | ||||||||||
| $httpClient = new Client([ | ||||||||||
| 'timeout' => 10, | ||||||||||
| ]); | ||||||||||
|
|
||||||||||
| // Initiate the auth object | ||||||||||
| $settings = [ | ||||||||||
| 'userName' => 'YOUR_USERNAME', | ||||||||||
| 'password' => 'YOUR_PASSWORD' | ||||||||||
| ]; | ||||||||||
| $apiUrl = 'https://mautic.example.com'; | ||||||||||
|
|
||||||||||
| $initAuth = new ApiAuth($httpClient); | ||||||||||
| $auth = $initAuth->newAuth($settings, 'BasicAuth'); | ||||||||||
|
|
||||||||||
| $api = new MauticApi(); | ||||||||||
| $contactsApi = $api->newApi('contacts', $auth, $apiUrl); | ||||||||||
| $contacts = $contactsApi->getList(); | ||||||||||
|
|
||||||||||
| .. vale off | ||||||||||
|
|
||||||||||
| Plain HTTP requests | ||||||||||
| =================== | ||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Turn it back on here. |
||||||||||
|
|
||||||||||
| .. vale on | ||||||||||
|
|
||||||||||
| 1. Combine the username and password of a Mautic User with a colon ``:``. For example, ``user:password``. | ||||||||||
| 2. Base64 encode this value. For example, with ``echo -n 'user:password' | base64``. This outputs something like ``dXNlcjpwYXNzd29yZA==``. | ||||||||||
| 3. Add an Authorization header to each API request as ``Authorization: Basic dXNlcjpwYXNzd29yZA==`` | ||||||||||
|
|
||||||||||
| Here's an example: | ||||||||||
|
|
||||||||||
| .. code-block:: console | ||||||||||
|
|
||||||||||
| curl -H "Authorization: Basic dXNlcjpwYXNzd29yZA==" https://mautic.example.com/api/contacts | ||||||||||
|
|
||||||||||
| OAuth2 | ||||||||||
| ****** | ||||||||||
|
|
||||||||||
| After enabling Mautic's API, the "API Credentials" menu item shows up in the administrator menu. You can create Client ID and Secret there, which you can then use in the next steps. | ||||||||||
|
|
||||||||||
| .. note:: | ||||||||||
|
|
||||||||||
| Mautic supports the ``authorization_code``, ``refresh_token`` and ``client_credentials`` grant types. | ||||||||||
|
|
||||||||||
| There are two main flows that Mautic supports: | ||||||||||
|
|
||||||||||
| .. list-table:: | ||||||||||
| :header-rows: 1 | ||||||||||
|
|
||||||||||
| * - Name | ||||||||||
| - Description | ||||||||||
| * - Authorization code flow | ||||||||||
| - This flow is best if you want Users to log in with their own Mautic accounts. All actions taken get registered as if the User performed them in Mautic's UI. | ||||||||||
| * - Client Credentials flow | ||||||||||
| - This flow is best for Machine-to-Machine, M2M, communications. For example, in cron jobs that run on at fixed times of the day. | ||||||||||
|
||||||||||
| - This flow is best for Machine-to-Machine, M2M, communications. For example, in cron jobs that run on at fixed times of the day. | |
| - This flow is best for Machine-to-Machine, M2M, communications. For example, in Cron jobs that run on at fixed times of the day. |
Vale fix
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These should be ~~~~ rather than ^^^^
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As above.
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As above
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd do a vale off / vale on around this heading, too.
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please convert this to a link macro using the make link command, and commit the link file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wrap this in a vale off / vale on, also
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| Authenticating the API Request | |
| Authenticating the API request |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's turn off Vale here as we are purposely going against the grammar rules to use a specific term.