用于Restful服务的Web2py认证以及应用程序用户

在web2py中,我们可以有如下所述的宁静服务,

auth.settings.allow_basic_login = True

@auth.requires_login()
@request.restful()
def api():
   def GET(s):
       return 'access granted, you said %s' % s
   return locals()

这项服务将由外部系统调用。 现在如何定义两个级别的服务使用情况。 一个可以访问服务的用户(外部系统)。 访问后,外部系统将使用Web应用程序向最终用户显示相关数据。 此外,将使用外部系统的最终用户需要登录,我将其存储在auth相关表中。 换句话说:最终用户使用基于外部Java的webapp进行注册和登录。 该应用程序会将我们的web2py视为宁静。 如果我们使用'@ auth.requires_login()'装饰器,它是否对API调用系统或最终用户进行身份验证? 还有人提到,api呼叫系统可以称为

curl --user name:password http://127.0.0.1:8000/myapp/default/api/hello

这意味着每次调用web2py API时,外部系统都会传递用户和密码。 即使如此,最终用户如何登录令牌也将被检查/发送。

我真的很感激有人可以回答这个问题。


基本上你想为web2py Restfull服务提供两种类型的身份验证。 这可以使用更通用的auth.requires装饰器来实现,

@auth.requires(custom_auth, requires_login=False)

custom_auth是模型中定义的函数,

def custom_auth():
     """Just a prototype that needs to be extended"""
     web2py_login = auth.user is not None
     other_login  = # do some other checks from a third party system
     return  web2py_login or other_login

请注意,基本身份验证不安全,应尽可能避免在生产中使用。 改为使用基于令牌的认证。

链接地址: http://www.djcxy.com/p/21999.html

上一篇: Web2py Authentication for Restful service and also application users

下一篇: Bypassing Login in android application