|
| 1 | +Authentication |
| 2 | +============== |
| 3 | + |
| 4 | +Github supports various authentication methods. Depending on the entity that authenticates and the Github API endpoint |
| 5 | +being called, only a subset of methods is available. |
| 6 | + |
| 7 | +All authentication methods require this import: |
| 8 | + |
| 9 | +.. code-block:: python |
| 10 | +
|
| 11 | + >>> from github import Auth |
| 12 | +
|
| 13 | +Login authentication |
| 14 | +-------------------- |
| 15 | + |
| 16 | +Users can authenticate by a login and password: |
| 17 | + |
| 18 | +.. code-block:: python |
| 19 | +
|
| 20 | + >>> auth = Auth.Login("user_login", "password") |
| 21 | + >>> g = Github(auth=auth) |
| 22 | + >>> g.get_user().login |
| 23 | + 'user_login' |
| 24 | +
|
| 25 | +OAuth token authentication |
| 26 | +-------------------------- |
| 27 | + |
| 28 | +Users can authenticate by a token: |
| 29 | + |
| 30 | +.. code-block:: python |
| 31 | +
|
| 32 | + >>> auth = Auth.Token("access_token") |
| 33 | + >>> g = Github(auth=auth) |
| 34 | + >>> g.get_user().login |
| 35 | + 'login' |
| 36 | +
|
| 37 | +App authentication |
| 38 | +------------------ |
| 39 | + |
| 40 | +A Github Apps authenticate by an application id and a private key. |
| 41 | + |
| 42 | +Note that there is only a limited set of endpoints that can be called when authenticated as a Github App. |
| 43 | +Instead of using ``github.Github``, entry point ``github.GithubIntegration`` should be used |
| 44 | +when authenticated as a Github App: |
| 45 | + |
| 46 | +.. code-block:: python |
| 47 | +
|
| 48 | + >>> auth = Auth.AppAuth(123456, private_key) |
| 49 | + >>> gi = GithubIntegration(auth=auth) |
| 50 | + >>> for installation in gi.get_installations(): |
| 51 | + ... installation.id |
| 52 | + '1234567' |
| 53 | +
|
| 54 | +App installation authentication |
| 55 | +------------------------------- |
| 56 | + |
| 57 | +A specific installation of a Github App can use the Github API like a normal user. |
| 58 | +It authenticates by the Github App authentication (see above) and the installation id. |
| 59 | +The ``AppInstallationAuth`` fetches an access token for the installation and handles its |
| 60 | +expiration timeout. The access token is refreshed automatically. |
| 61 | + |
| 62 | +.. code-block:: python |
| 63 | +
|
| 64 | + >>> auth = Auth.AppAuth(123456, private_key).get_installation_auth(installation_id, token_permissions) |
| 65 | + >>> g = Github(auth=auth) |
| 66 | + >>> g.get_repo("user/repo").name |
| 67 | + 'repo' |
0 commit comments