| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 768890a commit 91c17b7
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -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 | ======== | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -176,16 +176,11 @@ We recommend that you use `Credential helpers`_ to securely store your tokens. | |||
| 176 | 176 | to learn how to obtain a token. | |
| 177 | 177 | * - ``api_version`` | |
| 178 | 178 | - GitLab API version to use. Only ``4`` is available since 1.5.0. | |
| 179 | - * - ``http_username`` | ||
| 180 | - - Username for optional HTTP authentication | ||
| 181 | - * - ``http_password`` | ||
| 182 | - - Password for optional HTTP authentication | ||
| 183 | - | ||
| 184 | 179 | ||
| 185 | 180 | Credential helpers | |
| 186 | 181 | ------------------ | |
| 187 | 182 | ||
| 188 | - For all configuration options that contain secrets (``http_password``, | ||
| 183 | + For all configuration options that contain secrets (for example, | ||
| 189 | 184 | ``personal_token``, ``oauth_token``, ``job_token``), you can specify | |
| 190 | 185 | a helper program to retrieve the secret indicated by a ``helper:`` | |
| 191 | 186 | prefix. This allows you to fetch values from a local keyring store | |
@@ -229,7 +224,7 @@ In `/path/to/helper.sh`: | |||
| 229 | 224 | .. code-block:: bash | |
| 230 | 225 | ||
| 231 | 226 | #!/bin/bash | |
| 232 | - pass show path/to/password | head -n 1 | ||
| 227 | + pass show path/to/credentials | head -n 1 | ||
| 233 | 228 | ||
| 234 | 229 | CLI | |
| 235 | 230 | === | |
| Back | FazBrowse Home | New Git URL |
0 commit comments