Jump to >

djblets.webapi.oauth2_scopes

OAuth2 scope generation for WebAPI resources.

get_scope_dictionary()[source]

Return the scope dictionary.

This method requires WEB_API_ROOT_RESOURCE setting to point to an instance of the root resource for your WebAPI. Optionally, the WEB_API_SCOPE_DICT_CLASS (defaulting to djblets.webapi.oauth2_scopes.WebAPIScopeDictionary) can be set to specialize scope generation.

If the djblets.extensions app is being used, then the WEB_API_SCOPE_DICT_CLASS setting should be set to djblets.webapi.oauth2_scopes.ExtensionEnabledWebAPIScopeDictionary.

Returns:The scope dictionary.
Return type:WebAPIScopeDictionary
class WebAPIScopeDictionary(root_resource)[source]

Bases: object

A Web API scope dictionary.

This class knows how to build a list of available scopes from the WebAPI resource tree at runtime.

By default, it will only have to walk the API tree once, after which the value can be cached.

__init__(root_resource)[source]

Initialize the scope dictionary.

Parameters:root_resource (djblets.webapi.resources.base.WebAPIResource) – The root resource to walk in order to build scopes.
scope_dict[source]

The dictionary of scopes defined by this dictionary.

The value is cached so that it will only be recomputed when the dictionary is updated.

iterkeys()[source]

Iterate through all keys in the dictionary.

This is used by oauth2_provider when on Python 2.x to get the list of scope keys.

Yields:unicode – The key for each scope.
keys()[source]

Iterate through all keys in the dictionary.

This is used by oauth2_provider when on Python 3.x to get the list of scope keys.

Yields:unicode – The key for each scope.
clear()[source]

Clear all scopes from the dictionary.

The next attempt at fetching scopes will repopulate the dictionary from scratch.

__getitem__(key)[source]

Return the description of a given scope.

Parameters:key (unicode) – The scope’s key.
Returns:The scope’s description.
Return type:unicode
Raises:KeyError – The scope’s key was not in the dictionary.
__contains__(key)[source]

Return whether the dictionary has a particular scope.

Parameters:key (unicode) – The scope’s key.
Returns:True if the scope is in the dictionary.
Return type:bool
__repr__()[source]

Return a string representation of this object.

Returns:A string representation of this object.
Return type:unicode
class ExtensionEnabledWebAPIScopeDictionary(*args, **kwargs)[source]

Bases: djblets.webapi.oauth2_scopes.WebAPIScopeDictionary

A Web API scopes dictionary that supports extensions.

This scope dictionary is only required if your app is using the djblets.extensions app.

__init__(*args, **kwargs)[source]

Initialize the scope dictionary.

This adds signal handlers to ensure the dictionary stays up to date when extensions are initialized and uninitialized.

Parameters:
  • *args (tuple) – Positional arguments to pass to the parent class.
  • **kwargs (dict) – Keyword arguments to pass to the the parent class.
enable_web_api_scopes(*args, **kwargs)[source]

Enable WebAPI scopes.

The oauth2_provider.settings.oauth2_settings object will be patched so that scopes are correctly cached. The cache will be lazily updated after the scopes are updated.

Parameters:
  • *args (tuple) – Ignored positional arguments.
  • **kwargs (dict) – Ignored keyword arguments.