0

运行.py:

class HMACAuth(HMACAuth):
    def check_auth(self, userid, hmac_hash, headers, data, allowed_roles, resource, method):
        accounts = app.data.driver.db['accounts']
        user = accounts.find_one({'username': userid})
        if user and '_id' in user:
            secret_key = user['secret_key']
            self.set_request_auth_value(user['_id'])

        # in this implementation we only hash request data, ignoring the headers.
        hm = hmac.new(bytes(secret_key, encoding='utf-8'), data, sha1).digest()

        return user and base64.b64encode(hm).decode() == hmac_hash

设置.py:

vms = {
    'additional_lookup': {
        'url': 'regex("[\w]+")',
        'field': 'name',
    },
    'cache_control': '',
    'cache_expires': 0,
    'public_methods': [],
    'public_item_methods': [],
    'resource_methods': ['GET', 'POST'],
    'item_methods': ['GET','PATCH','DELETE'],
    'auth_field': 'user_id',
    'schema': vm_schema,
}

我的问题是每个用户在向localhost:5000/vms.
通过TokenAuth身份验证,这没有发生。
我错过了什么??

PS:Python 3.3.5 上的 Eve 0.5-dev

4

1 回答 1

0

由于基于令牌的身份验证一切正常,并且由于这两种方法之间没有什么真正不同,期望自定义类本身,我将围绕它的行为进行调查。

我将首先检查文档是否实际上以正确的user_id值存储,也许是使用 mongo shell。如果没有,请确保您正在检查的文档已在您的自定义 HMAC 类处于活动状态时保存。添加断点并跟踪您的代码,诸如此类的简单事情。希望这可以帮助

于 2014-10-28T10:15:29.933 回答