Skip to content
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

Adding documentation for the new auth plugin #3846

Merged
merged 13 commits into from
Sep 26, 2024
Merged
1 change: 1 addition & 0 deletions reference/extensions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ Contents:
extensions/hooks
extensions/binary_compatibility
extensions/profile_plugin
extensions/authorization_plugins
extensions/command_wrapper
extensions/package_signing

47 changes: 47 additions & 0 deletions reference/extensions/authorization_plugins.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
.. _reference_extensions_authorization_plugin:

ErniGH marked this conversation as resolved.
Show resolved Hide resolved
Authorization plugins
---------------------

Regarding authorization, we have two plugins: one focused on remote Conan servers authorization, ``auth_remote.py``, and another
focused on authorization for source file servers, ``auth_source.py``.

The idea behind these plugins is to create custom integrations with each user's secrets managers.

Auth remote plugin
+++++++++++++++++++
This first plugin is a Python script that receives a ``remote`` object and two optional parameters: ``user`` and
``password``. The output should be a tuple of the username and password that we want to use for that remote,
or ``None`` if no credentials are specified for that remote and we want Conan to follow the normal login flow.

This plugin is located at the path ``<CONAN_HOME>/extensions/plugins/auth_remote.py`` and must be manually created with the name
``auth_remote.py``, containing a function named ``auth_remote_plugin(remote, user=None, password=None)``.

Here we can see an example of a plugin implementation.

.. code-block:: python

def auth_remote_plugin(remote, user=None, password=None):
ErniGH marked this conversation as resolved.
Show resolved Hide resolved
if remote.url.startswith("https://artifactory.my-org/"):
return "admin", "password"


Auth source plugin
+++++++++++++++++++
This one is a Python script that receives an ``url`` as a parameter and outputs a dictionary with the credentials or
access token. It can also return ``None`` to indicate that Conan should proceed with its normal login flow.

This plugin is located at the path ``<CONAN_HOME>/extensions/plugins/auth_source.py`` and must be manually created with the name
``auth_source.py``, containing a function named ``auth_source_plugin(url)``.

Here we can see an example of a plugin implementation.

.. code-block:: python

def auth_source_plugin(url):
if url.startswith("https://my-sources-user-password.my-org/"):
return {'user': 'my-user', 'password': 'my-password'}
elif url.startswith("https://my-private-token-sources.my-org/"):
return {'token': 'my-secure-token'}


ErniGH marked this conversation as resolved.
Show resolved Hide resolved