Пример #1
0
    def __init__(self, rublon_consumer):
        super(RublonAPIGetAvailableFeatures, self).__init__(rublon_consumer)

        if not rublon_consumer.is_configured():
            raise RublonConfigurationError(rublon_consumer.TEMPLATE_CONFIG_ERROR)

        self.set_request_url(rublon_consumer.get_api_domain() + self.url_path)
Пример #2
0
    def auth(self, callback_url, user_id, user_email, extra_params=None):
        """Initializes the Rublon authentication transaction
        and returns the URL address to redirect user's browser
        or NULL if user's account is not protected.

        First, method checks the account's protection status in the Rublon server for current user.
        If user has protected this account, method returns the URL address.
        Redirect user's browser to this URL to start the Rublon authentication process.

        If Rublon user has deleted his Rublon account or Rublon API is not available at this time,
        method returns false. If so, just bypass Rublon and sign in the user.

        Notice: to use this method the configurations values (system token and secret key)
        must be provided to the constructor. If not, function will raise RublonConfigurationError."""

        if extra_params is None:
            extra_params = {}

        if not self.is_configured():
            raise RublonConfigurationError(self.TEMPLATE_CONFIG_ERROR)

        if self.get_lang():
            extra_params['lang'] = self.get_lang()

        try:
            api = RublonAPIBeginTransaction(self, callback_url, user_email, user_id, extra_params)
            api.perform()
            return api.get_web_uri()
        except UserNotFound_RublonAPIException:
            # bypass Rublon
            return None
        except RublonException:
            raise
Пример #3
0
 def __init__(self, rublon2factor):
     if not rublon2factor.is_configured():
         raise RublonConfigurationError(rublon2factor.TEMPLATE_CONFIG_ERROR)
     self.rublon = rublon2factor
     self.success_handler = None
     self.cancel_handler = None
     self.credentials = None
Пример #4
0
    def __init__(self, rublon_consumer):
        super(RublonAPINotification, self).__init__(rublon_consumer)

        if not rublon_consumer.is_configured():
            raise RublonConfigurationError(
                rublon_consumer.TEMPLATE_CONFIG_ERROR)

        self.notification_channel = None
        self.notification_title = None
        self.notification_url = None
        self.notification_type = None

        self.set_request_url(rublon_consumer.get_api_domain() + self.url_path)
Пример #5
0
    def __init__(self, rublon_consumer, profile_id, device_id):
        super(RublonAPICheckUserDevice, self).__init__(rublon_consumer)

        if not rublon_consumer.is_configured():
            raise RublonConfigurationError(
                rublon_consumer.TEMPLATE_CONFIG_ERROR)

        # Set request URL and parameters
        self.set_request_url(rublon_consumer.get_api_domain() + self.url_path)
        self.set_request_params({
            self.FIELD_PROFILE_ID: profile_id,
            self.FIELD_DEVICE_ID: device_id
        })
Пример #6
0
    def __init__(self, rublon_consumer, access_token):
        super(RublonAPILoginCredentials, self).__init__(rublon_consumer)

        if not rublon_consumer.is_configured():
            raise RublonConfigurationError(
                rublon_consumer.TEMPLATE_CONFIG_ERROR)

        # Set request URL and parameters
        url = rublon_consumer.get_api_domain() + self.url_path
        params = {
            self.FIELD_SYSTEM_TOKEN: rublon_consumer.get_system_token(),
            self.FIELD_ACCESS_TOKEN: access_token
        }
        self.set_request_url(url).set_request_params(params)
Пример #7
0
    def __init__(self, rublon_consumer, callback_url, user_email, user_id,
                 consumer_params):
        super(RublonAPIBeginTransaction, self).__init__(rublon_consumer)

        if not rublon_consumer.is_configured():
            raise RublonConfigurationError('')

        consumer_params[self.FIELD_SYSTEM_TOKEN] = rublon_consumer.system_token
        consumer_params[self.FIELD_USER_ID] = user_id
        consumer_params[self.FIELD_USER_EMAIL_HASH] = hash_data(
            user_email, self.HASH_ALG)
        if not consumer_params.get(RublonAuthParams.FIELD_FORCE_MOBILE_APP):
            consumer_params[self.FIELD_USER_EMAIL] = user_email.lower()
        consumer_params[self.FIELD_CALLBACK_URL] = callback_url

        url = rublon_consumer.get_api_domain() + self.URL_PATH
        self.set_request_url(url)
        self.set_request_params(consumer_params)
Пример #8
0
    def auth(self, callback_url, consumer_params=None):
        """Get authentication URL."""
        if not self.is_configured():
            raise RublonConfigurationError(self.TEMPLATE_CONFIG_ERROR)

        if consumer_params is None:
            consumer_params = {}

        if self.get_lang():
            consumer_params[RublonAuthParams.FIELD_LANG] = self.get_lang()

        try:
            begin_login_transaction = RublonAPIBeginLoginTransaction(self, callback_url, consumer_params)
            begin_login_transaction.perform()
            return begin_login_transaction.get_web_uri()
        except UserNotFound_RublonAPIException:
            # bypass Rublon
            return None
        except RublonException:
            raise
    def __init__(self, rublon_consumer, callback_url, consumer_params=None):
        if consumer_params is None:
            consumer_params = {}

        super(RublonAPIBeginLoginTransaction, self).__init__(rublon_consumer)

        if not rublon_consumer.is_configured():
            raise RublonConfigurationError(
                rublon_consumer.TEMPLATE_CONFIG_ERROR)

        consumer_params.update({
            self.FIELD_SYSTEM_TOKEN:
            rublon_consumer.get_system_token(),
            self.FIELD_CALLBACK_URL:
            callback_url
        })

        # Set request URL and parameters
        url = rublon_consumer.get_api_domain() + self.URL_PATH
        self.set_request_url(url).set_request_params(consumer_params)
Пример #10
0
    def __init__(self, rublon_consumer, access_token):
        """
        :type rublon_consumer RublonConsumer
        """
        super(RublonApiCredentials, self).__init__(rublon_consumer)

        if not rublon_consumer.is_configured():
            raise RublonConfigurationError(
                rublon_consumer.TEMPLATE_CONFIG_ERROR)

        if re.match(r'[a-zA-Z0-9]{100}', access_token) is None:
            raise RublonException(self.ERROR_ACCESS_TOKEN,
                                  RublonException.CODE_INVALID_ACCESS_TOKEN)

        self.response = {}

        # Set request URL and parameters
        url = rublon_consumer.get_api_domain() + self.url_path
        params = {
            self.FIELD_SYSTEM_TOKEN: rublon_consumer.get_system_token(),
            self.FIELD_ACCESS_TOKEN: access_token
        }
        self.set_request_url(url).set_request_params(params)