示例#1
0
    def authenticate(self, channel, socket_id, custom_data=None):
        """Used to generate delegated client subscription token.

        :param channel: name of the channel to authorize subscription to
        :param socket_id: id of the socket that requires authorization
        :param custom_data: used on presence channels to provide user info
        """
        channel = validate_channel(channel)

        if not channel_name_re.match(channel):
            raise ValueError('Channel should be a valid channel, got: %s' % channel)

        socket_id = validate_socket_id(socket_id)

        if custom_data:
            custom_data = json.dumps(custom_data, cls=self._json_encoder)

        string_to_sign = "%s:%s" % (socket_id, channel)

        if custom_data:
            string_to_sign += ":%s" % custom_data

        signature = sign(self.secret, string_to_sign)

        auth = "%s:%s" % (self.key, signature)
        result = {'auth': auth}

        if custom_data:
            result['channel_data'] = custom_data

        return result
 def test_custom_json_decoder(self):
     t = 1000 * time.time()
     body = u'{"nan": NaN, "time_ms": %f}' % t
     signature = sign(self.authentication_client.secret, body)
     data = self.authentication_client.validate_webhook(
         self.authentication_client.key, signature, body)
     self.assertEqual({u"nan": 99999, u"time_ms": t}, data)
示例#3
0
    def authenticate(self, channel, socket_id, custom_data=None):
        """Used to generate delegated client subscription token.

        :param channel: name of the channel to authorize subscription to
        :param socket_id: id of the socket that requires authorization
        :param custom_data: used on presence channels to provide user info
        """
        channel = validate_channel(channel)

        if not channel_name_re.match(channel):
            raise ValueError('Channel should be a valid channel, got: %s' %
                             channel)

        socket_id = validate_socket_id(socket_id)

        if custom_data:
            custom_data = json.dumps(custom_data, cls=self._json_encoder)

        string_to_sign = "%s:%s" % (socket_id, channel)

        if custom_data:
            string_to_sign += ":%s" % custom_data

        signature = sign(self.secret, string_to_sign)

        auth = "%s:%s" % (self.key, signature)
        result = {'auth': auth}

        if custom_data:
            result['channel_data'] = custom_data

        return result
示例#4
0
    def _generate_auth(self):
        self.body_md5 = hashlib.md5(self.body).hexdigest()
        self.query_params.update({
            'auth_key': self.client.key,
            'body_md5': six.text_type(self.body_md5),
            'auth_version': '1.0',
            'auth_timestamp': '%.0f' % time.time()
        })

        auth_string = '\n'.join(
            [self.method, self.path,
             make_query_string(self.query_params)])

        self.query_params['auth_signature'] = sign(self.client.secret,
                                                   auth_string)
示例#5
0
    def _generate_auth(self):
        self.body_md5 = hashlib.md5(self.body).hexdigest()
        self.query_params.update({
            'auth_key': self.client.key,
            'body_md5': six.text_type(self.body_md5),
            'auth_version': '1.0',
            'auth_timestamp': '%.0f' % time.time()})

        auth_string = '\n'.join([
            self.method,
            self.path,
            make_query_string(self.query_params)])

        self.query_params['auth_signature'] = sign(
            self.client.secret, auth_string)
    def _generate_auth(self):
        self.body_md5 = hashlib.md5(self.body).hexdigest()
        self.query_params.update({
            'auth_key':
            self.config.key,
            'body_md5':
            six.text_type(self.body_md5),
            'auth_version':
            '1.0',
            # this is what we want to override: the time.
            # 'auth_timestamp': '%.0f' % time.time()
            #  we want to make sure this is always valid, thus the next line:
            'auth_timestamp':
            '%.0f' % timeshift.actual_now().timestamp()
            # '%s' formats to unix timestamp =)
        })

        auth_string = '\n'.join(
            [self.method, self.path,
             make_query_string(self.query_params)])
        self.query_params['auth_signature'] = sign(self.config.secret,
                                                   auth_string)
    def authenticate(self, channel, socket_id, custom_data=None):
        """Used to generate delegated client subscription token.

        :param channel: name of the channel to authorize subscription to
        :param socket_id: id of the socket that requires authorization
        :param custom_data: used on presence channels to provide user info
        """
        channel = validate_channel(channel)

        if not channel_name_re.match(channel):
            raise ValueError('Channel should be a valid channel, got: %s' %
                             channel)

        socket_id = validate_socket_id(socket_id)

        if custom_data:
            custom_data = json.dumps(custom_data, cls=self._json_encoder)

        string_to_sign = "%s:%s" % (socket_id, channel)

        if custom_data:
            string_to_sign += ":%s" % custom_data

        signature = sign(self.secret, string_to_sign)

        auth = "%s:%s" % (self.key, signature)
        response_payload = {"auth": auth}

        if is_encrypted_channel(channel):
            shared_secret = generate_shared_secret(
                ensure_binary(channel, "channel"), self._encryption_master_key)
            shared_secret_b64 = base64.b64encode(shared_secret)
            response_payload["shared_secret"] = shared_secret_b64

        if custom_data:
            response_payload['channel_data'] = custom_data

        return response_payload
示例#8
0
 def verify(key, message, signature):
     return sign(key, message) == signature
示例#9
0
 def _sign(self, message):
     return sign(self.client.secret, message)
示例#10
0
 def verify(key, message, signature):
     return sign(key, message) == signature
示例#11
0
 def _sign(self, message):
     return sign(self.client.secret, message)