Authentication Web2py中的命令行身份验证

Authentication Web2py中的命令行身份验证,authentication,login,command-line-interface,web2py,pam,Authentication,Login,Command Line Interface,Web2py,Pam,我已经使用web2py为我的项目创建了一个web界面,并使用pam配置了登录。现在,我必须为相同的应用程序创建CLI。我找不到任何可以验证用户身份的方法(我们可以假设我要验证的用户已经登录到配置了pam并运行web2py的linux机器上)。首先,您需要找到登录用户的名称: username = os.getlogin() 然后强制登录: from gluon.storage import Storage from uuid import uuid4 session.auth = Storag

我已经使用web2py为我的项目创建了一个web界面,并使用pam配置了登录。现在,我必须为相同的应用程序创建CLI。我找不到任何可以验证用户身份的方法(我们可以假设我要验证的用户已经登录到配置了pam并运行web2py的linux机器上)。

首先,您需要找到登录用户的名称:

username = os.getlogin()
然后强制登录:

from gluon.storage import Storage
from uuid import uuid4
session.auth = Storage(user=user, last_visit=request.now,
                                   expiration=auth.settings.expiration,
                                   hmac_key = str(uuid4())

我们将要添加一个auth方法来在一行中完成此操作。

要添加到Massimo所说的内容中,现在已经实现了这一行登录。可以使用以下代码执行此操作:

#User_id is whatever the id is for the user you are forcing them to log in to
auth.login_user(user_id)

我在书中找不到任何关于此的文档,但您可以在源代码的glion.tools模块中亲自查看该方法。

我们如何使用此会话进行xmlrpc调用?+1作为示例。。。web2py中添加了一行程序了吗?如果是这样的话,您是否可以发布到文档的链接,或者以其他方式展示如何使用本机API?