Skip to content
This repository was archived by the owner on Jun 11, 2024. It is now read-only.

Commit 00117d5

Browse files
committed
atomx.Atomx.login takes totp parameter for users that have 2-factor auth enabled.
1 parent f308067 commit 00117d5

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

CHANGES.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
1.5.1 (unreleased)
2+
------------------
3+
4+
- :meth:`atomx.Atomx.login` takes ``totp`` parameter for users that have 2-factor auth enabled.
5+
6+
17
1.5
28
---
39

atomx/__init__.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,40 +36,44 @@ class Atomx(object):
3636
3737
:param str email: email address of your atomx user
3838
:param str password: password of your atomx user
39+
:param str totp: 6 digit auth token if the account has 2-factor authentication enabled.
3940
:param str api_endpoint: url for connections to the api
4041
(defaults to `https://api.atomx.com/{API_VERSION}`)
4142
:param bool save_response: If `True` save the last api response meta info
4243
(without the resource payload) in :attr:`.Atomx.last_response`. (default: `True`)
4344
:return: :class:`.Atomx` session to interact with the api
4445
"""
45-
def __init__(self, email, password,
46+
def __init__(self, email, password, totp=None,
4647
api_endpoint=API_ENDPOINT, save_response=True, expiration=None):
4748
self.auth_token = None
4849
self.user = None
4950
self.api_endpoint = api_endpoint.rstrip('/') + '/'
5051
self.save_response = save_response
5152
#: Contains the response of the last api call, if `save_response` was set `True`
5253
self.last_response = None
53-
self.login(email, password, expiration)
54+
self.login(email, password, totp, expiration)
5455

5556
@property
5657
def _auth_header(self):
5758
if self.auth_token:
5859
return {'Authorization': 'Bearer ' + self.auth_token}
5960

60-
def login(self, email, password, expiration=None):
61+
def login(self, email, password, totp=None, expiration=None):
6162
"""Gets new authentication token for user ``email``.
6263
6364
This method is automatically called in :meth:`__init__` so
6465
you rarely have to call this method directly.
6566
6667
:param str email: Email to use for login.
6768
:param str password: Password to use for login.
69+
:param str totp: 6 digit auth token if the account has 2-factor authentication enabled.
6870
:param int expiration: Number of seconds that the auth token should be valid. (optional)
6971
:return: None
7072
:raises: :class:`.exceptions.InvalidCredentials` if ``email``/``password`` is wrong
7173
"""
7274
json = {'email': email, 'password': password}
75+
if totp:
76+
json['totp'] = str(totp)
7377
if expiration:
7478
json['expiration'] = expiration
7579
r = requests.post(self.api_endpoint + 'login', json=json)

atomx/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
VERSION = '1.5'
1+
VERSION = '1.5.1b'
22
API_VERSION = 'v3'

0 commit comments

Comments
 (0)