gpt4 book ai didi

用于 Restful 服务和应用程序用户的 Web2py 身份验证

转载 作者:行者123 更新时间:2023-12-02 01:39:50 24 4
gpt4 key购买 nike

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

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()

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

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

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

如果有人能回答这个问题,我将不胜感激。

最佳答案

基本上,您需要两种类型的 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

请注意,基本身份验证是 not secure ,并且在生产中应尽可能避免。使用token based authentification反而。

关于用于 Restful 服务和应用程序用户的 Web2py 身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29039363/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com