def run(args): """This function will allow the current user to authorise a logout from the current session - this will be authorised by signing the request to logout Args: args (dict): contains identifying information about the session Returns: dict: contains data on the success of the logout request """ session_uid = args["session_uid"] try: authorisation = Authorisation.from_data(args["authorisation"]) except: authorisation = None try: signature = string_to_bytes(args["signature"]) except: signature = None login_session = LoginSession.load(uid=session_uid) login_session.set_logged_out(authorisation=authorisation, signature=signature)
def run(args): """This function will allow anyone to obtain the public keys for the passed login session """ try: session_uid = args["session_uid"] except: session_uid = None try: short_uid = args["short_uid"] except: short_uid = None try: scope = args["scope"] except: scope = None try: permissions = args["permissions"] except: permissions = None if session_uid: login_session = LoginSession.load(uid=session_uid, scope=scope, permissions=permissions) else: if short_uid is None: raise PermissionError( "You must specify either the session_uid or the short_uid " "of the login session") try: status = args["status"] except: raise PermissionError( "You must specify the status of the short_uid session you " "wish to query...") login_session = LoginSession.load(short_uid=short_uid, status=status, scope=scope, permissions=permissions) return_value = {} # only send information if the user had logged in! should_return_data = False if login_session.is_approved(): should_return_data = True return_value["public_key"] = login_session.public_key().to_data() elif login_session.is_logged_out(): should_return_data = True return_value["logout_datetime"] = \ datetime_to_string(login_session.logout_time()) if should_return_data: return_value["public_cert"] = \ login_session.public_certificate().to_data() return_value["scope"] = login_session.scope() return_value["permissions"] = login_session.permissions() return_value["user_uid"] = login_session.user_uid() return_value["session_status"] = login_session.status() return_value["login_message"] = login_session.login_message() return return_value
def run(args): """This function is called by the user to log in and validate that a session is authorised to connect Args: args (dict): contains identifying information about the user, short_UID, username, password and OTP code Returns: dict: contains a URI and a UID for this login """ short_uid = args["short_uid"] packed_credentials = args["credentials"] try: user_uid = args["user_uid"] except: user_uid = None try: remember_device = args["remember_device"] if remember_device: remember_device = True else: remember_device = False except: remember_device = False # get the session referred to by the short_uid sessions = LoginSession.load(short_uid=short_uid, status="pending") if isinstance(sessions, LoginSession): # we have many sessions to test... sessions = [sessions] result = None login_session = None last_error = None credentials = None for session in sessions: try: if credentials is None: credentials = Credentials.from_data( data=packed_credentials, username=session.username(), short_uid=short_uid) else: credentials.assert_matching_username(session.username()) result = UserAccount.login(credentials=credentials, user_uid=user_uid, remember_device=remember_device) login_session = session # success! break except Exception as e: last_error = e if result is None or login_session is None: # no valid logins raise last_error # we've successfully logged in login_session.set_approved(user_uid=result["user"].uid(), device_uid=result["device_uid"]) return_value = {} return_value["user_uid"] = login_session.user_uid() if remember_device: try: service = get_this_service(need_private_access=False) hostname = service.hostname() if hostname is None: hostname = "acquire" issuer = "%s@%s" % (service.service_type(), hostname) username = result["user"].name() device_uid = result["device_uid"] otp = result["otp"] provisioning_uri = otp.provisioning_uri(username=username, issuer=issuer) return_value["provisioning_uri"] = provisioning_uri return_value["otpsecret"] = otp.secret() return_value["device_uid"] = device_uid except: pass return return_value