@@ -9,6 +9,15 @@ python-gitlab only supports GitLab API v4. |
9 | 9 |
|
10 | 10 | To connect to GitLab.com or another GitLab instance, create a ``gitlab.Gitlab`` object: |
11 | 11 |
|
| 12 | +.. hint:: |
| 13 | + |
| 14 | + You can use different types of tokens for authenticated requests against the GitLab API. |
| 15 | + You will most likely want to use a resource (project/group) access token or a personal |
| 16 | + access token. |
| 17 | + |
| 18 | + For the full list of available options and how to obtain these tokens, please see |
| 19 | + https://docs.gitlab.com/ee/api/index.html#authentication. |
| 20 | + |
12 | 21 | .. code-block:: python |
13 | 22 |
|
14 | 23 | import gitlab |
@@ -37,9 +46,8 @@ To connect to GitLab.com or another GitLab instance, create a ``gitlab.Gitlab`` |
37 | 46 | # Define your own custom user agent for requests |
38 | 47 | gl = gitlab.Gitlab('https://gitlab.example.com', user_agent='my-package/1.0.0') |
39 | 48 |
|
40 | | - # make an API request to create the gl.user object. This is mandatory if you |
41 | | - # use the username/password authentication - not required for token authentication, |
42 | | - # and will not work with job tokens. |
| 49 | + # make an API request to create the gl.user object. This is not required but may be useful |
| 50 | + # to validate your token authentication. Note that this will not work with job tokens. |
43 | 51 | gl.auth() |
44 | 52 |
|
45 | 53 | You can also use configuration files to create ``gitlab.Gitlab`` objects: |
@@ -68,18 +76,16 @@ configuration files. |
68 | 76 | Note on password authentication |
69 | 77 | ------------------------------- |
70 | 78 |
|
71 | | -The ``/session`` API endpoint used for username/password authentication has |
72 | | -been removed from GitLab in version 10.2, and is not available on gitlab.com |
73 | | -anymore. Personal token authentication is the preferred authentication method. |
| 79 | +GitLab has long removed password-based basic authentication. You can currently still use the |
| 80 | +`resource owner password credentials <https://docs.gitlab.com/ee/api/oauth2.html#resource-owner-password-credentials-flow>`_ |
| 81 | +flow to obtain an OAuth token. |
74 | 82 |
|
75 | | -If you need username/password authentication, you can use cookie-based |
76 | | -authentication. You can use the web UI form to authenticate, retrieve cookies, |
77 | | -and then use a custom ``requests.Session`` object to connect to the GitLab API. |
78 | | -The following code snippet demonstrates how to automate this: |
79 | | -https://gist.github.com/gpocentek/bd4c3fbf8a6ce226ebddc4aad6b46c0a. |
| 83 | +However, we do not recommend this as it will not work with 2FA enabled, and GitLab is removing |
| 84 | +ROPC-based flows without client IDs in a future release. We recommend you obtain tokens for |
| 85 | +automated workflows as linked above or obtain a session cookie from your browser. |
80 | 86 |
|
81 | | -See `issue 380 <https://github.com/python-gitlab/python-gitlab/issues/380>`_ |
82 | | -for a detailed discussion. |
| 87 | +For a python example of password authentication using the ROPC-based OAuth2 |
| 88 | +flow, see `this Ansible snippet <https://github.com/ansible-collections/community.general/blob/1c06e237c8100ac30d3941d5a3869a4428ba2974/plugins/module_utils/gitlab.py#L86-L92>`_. |
83 | 89 |
|
84 | 90 | Managers |
85 | 91 | ======== |
|