Source code for api.authentication.v1.sms.sms_authenticate
"""Autogenerated API"""
from argus_cli.plugin import register_command
[docs]@register_command(extending=("authentication","v1","sms","authenticate"))
def authenticate(
userName: str = None,
domain: str = None,
mode: str = None,
passcode: str = None,
cookie: str = None,
json: bool = True,
verify: bool = True,
apiKey: str = None,
authentication: dict = {}
) -> dict:
"""Initiate a new user session using SMS authentication (PUBLIC)
Requires SMS authentication to be enabled on the server, and for the user.
Use /methods to check which authentication methods are available on the server.
This is a 2-step authentication method. The first request should have mode PASSWORD, and carry username and static password.
The request will return a challenge, carrying a session cookie.When the SMS code is received, submit a new request with mode VERIFICATION, the username, SMS code (in the passcode) and the session cookie returned in the challenge.
:param str userName: Username to authenticate
:param str domain: User domain
:param str mode: Use PASSWORD for initial request, and SMS to respond with SMS code
:param str passcode: Password or SMS code
:param str cookie: When responding with SMS code, set the SMS session cookie returned by challenge
:raises AuthenticationFailedException: on 401
:raises ValidationErrorException: on 412
:raises AccessDeniedException: on 403
:raises NotFoundException: on 404
:returns: {'offset': 369, 'limit': 8, 'responseCode': 200, 'count': 429, 'metaData': {'additionalProperties': {}}, 'messages': [{'message': 'Network interest yard act.', 'messageTemplate': 'Us break future while.', 'field': 'Loss significant thousand check trip should but write.', 'parameter': {}, 'timestamp': 1488987845}], 'currentPage': 631, 'size': 891}
"""
from requests import post
from argus_api.exceptions import http
url = "https://portal.mnemonic.no/web/api/authentication/v1/sms/authenticate".format()
headers = {
'Content-Type': 'application/json',
'User-Agent': 'ArgusToolbelt/'
}
if apiKey:
headers["Argus-API-Key"] = apiKey
elif authentication and isinstance(authentication, dict):
headers.update(authentication)
elif callable(authentication):
headers.update(authentication(url))
body = {
"userName": userName,
"domain": domain,
"mode": mode,
"passcode": passcode,
"cookie": cookie
}
response = post(url,
json=body if body else None,
verify=verify,
headers=headers
)
if response.status_code == 401:
raise http.AuthenticationFailedException(response)
elif response.status_code == 403:
raise http.AccessDeniedException(response)
elif response.status_code == 412:
raise http.ValidationErrorException(response)
elif response.status_code == 404:
raise http.ObjectNotFoundException(response)
return response.json() if json else response