neris-api-client 1.0.0__tar.gz → 1.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: neris_api_client
3
- Version: 1.0.0
3
+ Version: 1.1.0
4
4
  Summary: NERIS API Client
5
5
  Author-email: Ben Coleman <ben.coleman@ul.org>
6
6
  Project-URL: Homepage, https://github.com/ulfsri/neris-api-client
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "neris_api_client"
7
- version = "1.0.0"
7
+ version = "1.1.0"
8
8
  authors = [
9
9
  { name="Ben Coleman", email="ben.coleman@ul.org" },
10
10
  ]
@@ -116,11 +116,37 @@ class _NerisApiClient:
116
116
 
117
117
  @_fetch_cognito_config
118
118
  def _initiate_auth(self) -> None:
119
- res = self._cognito.initiate_auth(
120
- AuthFlow="USER_PASSWORD_AUTH",
121
- AuthParameters={"USERNAME": self._username, "PASSWORD": self._password},
122
- ClientId=self._cognito_config["client_id"],
123
- )
119
+ try:
120
+ res = self._cognito.initiate_auth(
121
+ AuthFlow="USER_PASSWORD_AUTH",
122
+ AuthParameters={"USERNAME": self._username, "PASSWORD": self._password},
123
+ ClientId=self._cognito_config["client_id"],
124
+ )
125
+ except self._cognito.exceptions.LimitExceededException as e:
126
+ print(e.response["message"])
127
+ return
128
+
129
+ if "AuthenticationResult" not in res:
130
+ challenge_name = res["ChallengeName"]
131
+
132
+ answer = input(f"Provide MFA auth challenge answer for {challenge_name}: ")
133
+
134
+ while True:
135
+ try:
136
+ res = self._cognito.respond_to_auth_challenge(
137
+ ClientId=self._cognito_config["client_id"],
138
+ Session=res["Session"],
139
+ ChallengeName=challenge_name,
140
+ ChallengeResponses={
141
+ "USERNAME": self._username,
142
+ f"{challenge_name}_CODE": answer,
143
+ },
144
+ )
145
+ break
146
+ except self._cognito.exceptions.CodeMismatchException as e:
147
+ print(e.response["message"])
148
+ # Keep trying until the answer is correct
149
+ answer = input(f"Provide MFA auth challenge answer for {challenge_name}: ")
124
150
 
125
151
  self._access_token = res["AuthenticationResult"]["AccessToken"]
126
152
  self._refresh_token = res["AuthenticationResult"]["RefreshToken"]