@@ -264,6 +264,19 @@ def start_session(self):
264
264
self ._get_session (self .__auth )
265
265
266
266
267
+ class TokenAuth (AuthBase ):
268
+ """Bearer Token Authentication"""
269
+
270
+ def __init__ (self , token : str ):
271
+ # setup any auth-related data here
272
+ self ._token = token
273
+
274
+ def __call__ (self , r : requests .PreparedRequest ):
275
+ # modify and return the request
276
+ r .headers ["authorization" ] = f"Bearer { self ._token } "
277
+ return r
278
+
279
+
267
280
class JIRA :
268
281
"""User interface to Jira.
269
282
@@ -325,10 +338,10 @@ def __init__(
325
338
self ,
326
339
server : str = None ,
327
340
options : Dict [str , Union [str , bool , Any ]] = None ,
328
- basic_auth : Union [None , Tuple [str , str ]] = None ,
341
+ basic_auth : Optional [Tuple [str , str ]] = None ,
342
+ token_auth : Optional [str ] = None ,
329
343
oauth : Dict [str , Any ] = None ,
330
344
jwt : Dict [str , Any ] = None ,
331
- token_auth : str = None ,
332
345
kerberos = False ,
333
346
kerberos_options : Dict [str , Any ] = None ,
334
347
validate = False ,
@@ -348,8 +361,8 @@ def __init__(
348
361
or ``atlas-run-standalone`` commands. By default, this instance runs at
349
362
``http://localhost:2990/jira``. The ``options`` argument can be used to set the Jira instance to use.
350
363
351
- Authentication is handled with the ``basic_auth`` argument. If authentication is supplied (and is
352
- accepted by Jira), the client will remember it for subsequent requests.
364
+ Authentication is handled with the ``basic_auth`` or ``token_auth`` argument.
365
+ If authentication is supplied (and is accepted by Jira), the client will remember it for subsequent requests.
353
366
354
367
For quick command line access to a server, see the ``jirashell`` script included with this distribution.
355
368
@@ -397,7 +410,7 @@ def __init__(
397
410
398
411
Example jwt structure: ``{'secret': SHARED_SECRET, 'payload': {'iss': PLUGIN_KEY}}``
399
412
400
- token_auth (str): A string containg the token necessary for (PAT) token authorization.
413
+ token_auth (str): A string containing the token necessary for (PAT) bearer token authorization.
401
414
402
415
validate (bool): If true it will validate your credentials first. Remember that if you are accessing Jira
403
416
as anonymous it will fail to instantiate.
@@ -3417,16 +3430,19 @@ def _create_jwt_session(
3417
3430
self ._session .verify = bool (self ._options ["verify" ])
3418
3431
self ._session .auth = jwt_auth
3419
3432
3420
- def _create_token_session (self , token_auth : str , timeout ):
3433
+ def _create_token_session (
3434
+ self ,
3435
+ token_auth : str ,
3436
+ timeout : Optional [Union [Union [float , int ], Tuple [float , float ]]],
3437
+ ):
3421
3438
"""
3422
3439
Creates token-based session.
3423
3440
Header structure: "authorization": "Bearer <token_auth>"
3424
3441
"""
3425
3442
verify = self ._options ["verify" ]
3426
3443
self ._session = ResilientSession (timeout = timeout )
3427
3444
self ._session .verify = verify
3428
- token_auth = TokenAuth (token_auth )
3429
- self ._session .auth = token_auth
3445
+ self ._session .auth = TokenAuth (token_auth )
3430
3446
3431
3447
def _set_avatar (self , params , url , avatar ):
3432
3448
data = {"id" : avatar }
@@ -4826,13 +4842,3 @@ def __init__(self, options=None, basic_auth=None, oauth=None, async_=None):
4826
4842
self , options = options , basic_auth = basic_auth , oauth = oauth , async_ = async_
4827
4843
)
4828
4844
4829
- class TokenAuth (AuthBase ):
4830
- """Token Authentication"""
4831
- def __init__ (self , token : str ):
4832
- # setup any auth-related data here
4833
- self ._token = token
4834
-
4835
- def __call__ (self , r ):
4836
- # modify and return the request
4837
- r .headers ['authorization' ] = "Bearer " + self ._token
4838
- return r
0 commit comments