在pythoneve中定制资源端点授权

2024-10-06 12:36:31 发布

您现在位置:Python中文网/ 问答频道 /正文

我已经在pythoneve中实现了我的web服务。我有几个端点,比如人,地址等。在

端点架构定义如下:

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 ..


Tags: cacheagegettitleschemaitempeoplepost
1条回答
网友
1楼 · 发布于 2024-10-06 12:36:31

您可能需要使用User Restricted Resource Access功能。引用文件:

When this feature is enabled, each stored document is associated with the account that created it. This allows the API to transparently serve only account-created documents on all kinds of requests: read, edit, delete and of course create. User authentication needs to be enabled for this to work properly.

相关问题 更多 >