【问题标题】:Customizing Authorization on resource endpoints in Python EVE在 Python EVE 中自定义资源端点的授权
【发布时间】:2015-05-24 12:36:17
【问题描述】:

我已经在 Python eve 中实现了我的网络服务。我有几个端点,例如人员、地址等。

端点架构定义如下:-

RESOURCE_METHODS = ['GET', 'POST', 'DELETE']

ITEM_METHODS = ['GET', 'PATCH', 'PUT', 'DELETE']

people = {
  'item_title': 'person',
  'cache_control': 'max-age=10,must-revalidate',
  'cache_expires': 10,
  'resource_methods': ['GET', 'POST'],
  'schema': dbtableSchema.schema_people,
  'public_methods': ['POST']
  }

org = {
  'item_title': 'org',
  'cache_control': 'max-age=10,must-revalidate',
  'cache_expires': 10,
  'resource_methods': ['GET', 'POST'],
  'schema': dbtableSchema.schema_people_org
  }

puburl = {
  'item_title': 'puburl',
  'cache_control': 'max-age=10,must-revalidate',
  'cache_expires': 10,
  'resource_methods': ['GET', 'POST'],
  'schema': dbtableSchema.schema_people_pub_url
  }

address = {
  'item_title': 'address',
  'cache_control': 'max-age=10,must-revalidate',
  'cache_expires': 10,
  'resource_methods': ['GET', 'POST'],
  'schema': dbtableSchema.schema_people_address
 }

contactnumber = {
  'item_title': 'contactnumber',
  'cache_control': 'max-age=10,must-revalidate',
  'cache_expires': 10,
  'resource_methods': ['GET', 'POST'],
  'schema': dbtableSchema.schema_people_contact_number
 }

template = {
  'item_title': 'template',
  'cache_control': 'max-age=10,must-revalidate',
  'cache_expires': 10,
  'resource_methods': ['GET', 'POST'],
  'schema': dbtableSchema.schema_template
 }

usersharedcontacts = {
  'item_title': 'usersharedcontacts',
  'cache_control': 'max-age=10,must-revalidate',
  'cache_expires': 10,
  'resource_methods': ['GET', 'POST'],
  'schema': dbtableSchema.schema_people_with_user_shared_contacts
 }

cardholder = {
  'item_title': 'cardholder',
  'cache_control': 'max-age=10,must-revalidate',
  'cache_expires': 10,
  'resource_methods': ['GET', 'POST'],
  'schema': dbtableSchema.schema_people_card_holder
 }

DOMAIN = {
  'people': people,
  'org': org,
  'puburl': puburl,
  'address': address,
  'contactnumber': contactnumber,
  'template': template,
  'usersharedcontacts': usersharedcontacts,
  'cardholder': cardholder
 }

我已经实现了身份验证,以使people 端点上的POST 调用免费,即无需任何身份验证即可创建用户配置文件,并且数据库中的people 表将被填充。

我现在想确保一旦用户通过身份验证,他/她就不能修改其他用户的信息。 Python EVE 有没有办法处理这个问题。

[EDIT]:- There was some bug in my code , @Niccola's Solution worked properly ..

【问题讨论】:

    标签: python web-services python-2.7 eve


    【解决方案1】:

    您可能想要使用User Restricted Resource Access 功能。引用文档:

    启用此功能后,每个存储的文档都与创建它的帐户相关联。 这允许 API 仅针对各种请求透明地提供帐户创建的文档:读取、编辑、删除,当然还有创建。需要启用用户身份验证才能正常工作。

    【讨论】:

    • 嗨@nicola-iarocci,我浏览了EVE官方文档页面上描述的文档,我无法弄清楚采用这种方法的确切步骤。如果我能得到一些代码 sn-ps 和所需的确切更改,那将非常有帮助。
    • 您的解决方案工作正常,感谢您帮助我.. :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-25
    • 2016-04-10
    • 2022-11-04
    • 1970-01-01
    • 1970-01-01
    • 2019-06-26
    相关资源
    最近更新 更多