使用API​​在Odoo 13中检索哈希密码

问题描述

odoo 11中,我可以从 res_users 表的 password_crypt 字段中检索哈希密码,但这在 odoo 13 中不起作用更多。

我使用odoo 11凭据登录到无法集成在odoo中的其他应用程序。由于密码似乎只写,因此该身份验证停止工作。现在,我正在寻找一种方法获取odoo密码的读取权限,是否有任何线索使用API​​做到这一点?

我使用以下python测试代码,但密码字段为空:

import xmlrpclib

common = xmlrpclib.ServerProxy('{}/xmlrpc/2/common'.format(url))
uid = common.authenticate(db,username,password,{})
models = xmlrpclib.ServerProxy('{}/xmlrpc/2/object'.format(url))

user = models.execute_kw(db,uid,'res.users','search_read',[[['id','=',2]]],{})[0]

print user

有什么想法如何读取仅写哈希密码?

解决方法

由于read()上的res.users方法被覆盖以排除某些字段(例如密码字段),因此我(不*)建议在res.users上创建一个方法这样的SQL读取:

def read_password(self):
    self.ensure_one()
    self.env.cr.execute("SELECT password FROM res_users WHERE id=%s",self.id)

*免责声明:Odoo隐藏密码字段是有原因的,因此在这里您实际上是在绕过Odoo的安全性。您将需要三重确保此方法是100%安全的。一些想法:

  • 添加对正确的API密钥的检查
  • 仅允许特定用户执行此方法
  • 仅允许某个IP源执行此方法