Jump to >

This documentation covers Djblets 2.0. You can see the latest Djblets documentation or all other versions.


Web API resource support for OAuth2 token access.

class ResourceOAuth2TokenMixin[source]

Bases: object

Augments a WebAPIResource to support OAuth2 tokens.

Any WebAPIResource subclass making use of this mixin can accept requests backed by an OAuth2 token and will restrict the request to that token’s allowed scopes.

It is recommended that all resources in a project inherit from a base resource that inherits both from this mixin and from WebAPIResource.

oauth2_token_access_allowed = True[source]

Whether or not this resource is accessible when using an OAuth2 token.

HTTP_SCOPE_METHOD_MAP = {u'DELETE': u'destroy', u'GET': u'read', u'HEAD': u'read', u'OPTIONS': u'read', u'POST': u'write', u'PUT': u'write'}[source]

A mapping of HTTP methods to the type of scope required.

These will be used with scope_name to generate the full required scope, e.g. scope_name:read.


The ID used for required scopes.

This defaults to the name of the resource, but can be overridden in case the name is not specific enough or there’s a conflict.

If the resource allows WebAPI tokens in addition to OAuth2 tokens, this will default to the resource’s policy ID (which defaults to its name).

call_method_view(request, method, view, *args, **kwargs)[source]

Check token scopes and call the API method handler.

  • request (django.http.HttpRequest) – The current HTTP request.
  • method (unicode) – The HTTP method of the request.
  • view (callable) – The view function to call.
  • *args (tuple) – Additional positional arguments.
  • **kwargs (dict) – Additional keyword arguments.

One of the following:

Return type: