0
run.py:eve U.R.R.A.不HMAC工作
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
settings.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,
}
我的問題是,每個用戶都接收所有的虛擬機信息時,他/她發送GET請求到localhost:5000/vms
。
由於TokenAuth
認證沒有發生。
我在想什麼?
PS:對Python的前夜0.5-dev的3.3.5
這很奇怪!創建的用戶的'_id'是'544ff79fe555c028869380f7',而創建的vms的'_id'是'544ff79fe555c028869380f8'和'544ff79fe555c028869380f9'。這怎麼可能? :O 如果我編寫'print(user ['_ id'])'它可以,但它存儲了一個不同的值:/ – polslinux 2014-10-28 20:12:16
問題是字段'user_id'不是用HMACAuth類創建的。我不明白爲什麼我會得到這種奇怪的行爲... – polslinux 2014-10-28 21:17:32
我檢查與'self.get_request_auth_value()'和值是正確的:(所以爲什麼它不存儲在數據庫? - 。 – polslinux 2014-10-28 21:59:45