Skip to content

Commit 65096b6

Browse files
authored
add token auth to docs, update auth examples file (#1216)
1 parent 6ee9e34 commit 65096b6

File tree

3 files changed

+59
-50
lines changed

3 files changed

+59
-50
lines changed

docs/examples.rst

+47-14
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ Here's a quick usage example:
88

99
.. literalinclude:: ../examples/basic_use.py
1010

11-
Another example shows how to authenticate with your Jira username and password:
11+
Another example with methods to authenticate with your Jira:
1212

13-
.. literalinclude:: ../examples/basic_auth.py
13+
.. literalinclude:: ../examples/auth.py
1414

1515
This example shows how to work with GreenHopper:
1616

@@ -23,7 +23,7 @@ Quickstart
2323
Initialization
2424
--------------
2525

26-
Everything goes through the ``JIRA`` object, so make one::
26+
Everything goes through the :py:class:`jira.client.JIRA` object, so make one::
2727

2828
from jira import JIRA
2929

@@ -40,49 +40,56 @@ Authentication
4040
--------------
4141

4242
At initialization time, jira-python can optionally create an HTTP BASIC or use OAuth 1.0a access tokens for user
43-
authentication. These sessions will apply to all subsequent calls to the ``JIRA`` object.
43+
authentication. These sessions will apply to all subsequent calls to the :py:class:`jira.client.JIRA` object.
4444

4545
The library is able to load the credentials from inside the ~/.netrc file, so put them there instead of keeping them in your source code.
4646

4747
Cookie Based Authentication
4848
^^^^^^^^^^^^^^^^^^^^^^^^^^^
4949

50+
.. warning::
51+
This method of authentication is no longer supported on Jira Cloud. You can find the deprecation notice `here <https://developer.atlassian.com/cloud/jira/platform/deprecation-notice-basic-auth-and-cookie-based-auth>`_.
52+
53+
For Jira Cloud use the basic_auth= :ref:`basic-auth-api-token` authentication
54+
5055
Pass a tuple of (username, password) to the ``auth`` constructor argument::
5156

5257
auth_jira = JIRA(auth=('username', 'password'))
5358

5459
Using this method, authentication happens during the initialization of the object. If the authentication is successful,
5560
the retrieved session cookie will be used in future requests. Upon cookie expiration, authentication will happen again transparently.
5661

57-
.. warning::
58-
This method of authentication is no longer supported on Jira Cloud. You can find the deprecation notice `here <https://developer.atlassian.com/cloud/jira/platform/deprecation-notice-basic-auth-and-cookie-based-auth>`_.
59-
60-
For Jira Cloud use the basic_auth= :ref:`basic-auth-api-token` authentication
6162

6263
HTTP BASIC
6364
^^^^^^^^^^
6465

6566
(username, password)
6667
""""""""""""""""""""
6768

68-
Pass a tuple of (username, password) to the ``basic_auth`` constructor argument::
69-
70-
auth_jira = JIRA(basic_auth=('username', 'password'))
71-
7269
.. warning::
7370
This method of authentication is no longer supported on Jira Cloud. You can find the deprecation notice `here <https://developer.atlassian.com/cloud/jira/platform/deprecation-notice-basic-auth-and-cookie-based-auth>`_
7471

75-
For Jira Cloud use the basic_auth= :ref:`basic-auth-api-token` authentication
72+
For Jira Cloud use the basic_auth= :ref:`basic-auth-api-token` authentication.
73+
For Self Hosted Jira (Server, Data Center), consider the `Token Auth`_ authentication.
74+
75+
Pass a tuple of (username, password) to the ``basic_auth`` constructor argument::
76+
77+
auth_jira = JIRA(basic_auth=('username', 'password'))
7678

7779
.. _basic-auth-api-token:
7880

7981
(username, api_token)
8082
"""""""""""""""""""""
8183

82-
Or pass a tuple of (email, api_token) to the ``basic_auth`` constructor argument (JIRA cloud)::
84+
85+
Or pass a tuple of (email, api_token) to the ``basic_auth`` constructor argument (JIRA Cloud)::
8386

8487
auth_jira = JIRA(basic_auth=('email', 'API token'))
8588

89+
.. seealso::
90+
For Self Hosted Jira (Server, Data Center), refer to the `Token Auth`_ Section.
91+
92+
8693
OAuth
8794
^^^^^
8895

@@ -112,6 +119,32 @@ Pass a dict of OAuth properties to the ``oauth`` constructor argument::
112119
See https://confluence.atlassian.com/display/JIRA/Configuring+OAuth+Authentication+for+an+Application+Link for details
113120
on configuring an OAuth provider for Jira.
114121

122+
Token Auth
123+
^^^^^^^^^^
124+
125+
126+
Jira Cloud
127+
""""""""""
128+
129+
This is also referred to as an API Token in the
130+
`Jira Cloud documentation <https://support.atlassian.com/atlassian-account/docs/manage-api-tokens-for-your-atlassian-account/>`_ ::
131+
132+
133+
.. code-block:: python
134+
135+
auth_jira = JIRA(basic_auth=('email', 'API token'))
136+
137+
138+
Jira Self Hosted (incl. Jira Server/Data Center)
139+
""""""""""""""""""""""""""""""""""""""""""""""""
140+
141+
This is also referred to as Personal Access Tokens (PATs) in the
142+
`Self-Hosted Documentation <https://confluence.atlassian.com/enterprise/using-personal-access-tokens-1026032365.html>`_.
143+
The is available from Jira Core >= 8.14::
144+
145+
auth_jira = JIRA(token_auth='API token')
146+
147+
115148
Kerberos
116149
^^^^^^^^
117150

examples/basic_auth.py examples/auth.py

+12-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
# This script shows how to connect to a Jira instance with a
2-
# username and password over HTTP BASIC authentication.
1+
"""Some simple authentication examples.
2+
"""
33

44
from collections import Counter
55
from typing import cast
@@ -8,11 +8,16 @@
88
from jira.client import ResultList
99
from jira.resources import Issue
1010

11-
# By default, the client will connect to a Jira instance started from the Atlassian Plugin SDK.
12-
# See
13-
# https://developer.atlassian.com/display/DOCS/Installing+the+Atlassian+Plugin+SDK
14-
# for details.
15-
jira = JIRA(basic_auth=("admin", "admin")) # a username/password tuple
11+
# Some Authentication Methods
12+
jira = JIRA(
13+
basic_auth=("admin", "admin"), # a username/password tuple [Not recommended]
14+
# basic_auth=("email", "API token"), # Jira Cloud: a username/token tuple
15+
# token_auth="API token", # Self-Hosted Jira (e.g. Server): the PAT token
16+
# auth=("admin", "admin"), # a username/password tuple for cookie auth [Not recommended]
17+
)
18+
19+
# Who has authenticated
20+
myself = jira.myself()
1621

1722
# Get the mutable application properties for this server (requires
1823
# jira-system-administrators permission)

examples/cookie_auth.py

-29
This file was deleted.

0 commit comments

Comments
 (0)