Skip to content

Field-based authorization #88

@msander

Description

@msander

I wonder how to handle field-based authorization (i.e. a schema which is based on the request).

In webargs.core._get_schema the argmap is defined as

:param argmap: Either a `marshmallow.Schema`, `dict`
            of argname -> `marshmallow.fields.Field` pairs, or a callable that returns
            a `marshmallow.Schema` instance.

From my understanding aiohttp-apispec currently just supports passing a schema instance. For field-based authorization a callable that returns a schema instance would be required. Nevertheless, we still need to be able to create a schema from that callable without a request to be able to generate the swagger docs.

Maybe something like

def generate_schema(request):
  if request is None:
      return FullSchema()
  elif request.user.is_admin():
      return FullSchema()
  else:
      return NormalSchema()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions