djblets.webapi.oauth2_scopes¶
OAuth2 scope generation for WebAPI resources.
- get_scope_dictionary() WebAPIScopeDictionary[source]¶
Return the scope dictionary.
This method requires
WEB_API_ROOT_RESOURCEsetting to point to an instance of the root resource for your WebAPI. Optionally, theWEB_API_SCOPE_DICT_CLASS(defaulting todjblets.webapi.oauth2_scopes.WebAPIScopeDictionary) can be set to specialize scope generation.If the
djblets.extensionsapp is being used, then theWEB_API_SCOPE_DICT_CLASSsetting should be set todjblets.webapi.oauth2_scopes.ExtensionEnabledWebAPIScopeDictionary.- Returns:
The scope dictionary.
- Return type:
- class WebAPIScopeDictionary(root_resource: WebAPIResource)[source]¶
-
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: WebAPIResource) None[source]¶
Initialize the scope dictionary.
- Parameters:
root_resource (
djblets.webapi.resources.base.WebAPIResource) – The root resource to walk in order to build scopes.
- resource_trees: set[WebAPIResource]¶
The set of resource trees included in the API.
- __bool__() bool[source]¶
Return whether the object is truthy.
- Returns:
Trueif the scopes dictionary is non-empty.- Return type:
- __iter__() Iterator[str][source]¶
Iterate over the keys in the dictionary.
- Yields:
str– Each scope key.
- __len__() int[source]¶
Return the size of the scope dictionary.
- Returns:
The size of the scope dictionary.
- Return type:
- __repr__() str[source]¶
Return a string representation of this object.
- Returns:
A string representation of this object.
- Return type:
- property scope_dict: dict[str, str][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.
- clear() None[source]¶
Clear all scopes from the dictionary.
The next attempt at fetching scopes will repopulate the dictionary from scratch.
- keys() KeysView[str][source]¶
Iterate through all keys in the dictionary.
This is used by oauth2_provider to get the list of scope keys.
- Returns:
The key for each scope.
- Return type:
- items() ItemsView[str, str][source]¶
Iterate through all items in the dictionary.
- Returns:
The key for each scope.
- Return type:
- values() ValuesView[str][source]¶
Iterate through all values in the dictionary.
- Returns:
The key for each scope.
- Return type:
- __abstractmethods__ = frozenset({})¶
- __annotations__ = {'_scope_dict': 'dict[str, str]', 'resource_trees': 'set[WebAPIResource]'}¶
- __orig_bases__ = (collections.abc.Mapping[str, str],)¶
- class ExtensionEnabledWebAPIScopeDictionary(*args, **kwargs)[source]¶
Bases:
WebAPIScopeDictionaryA Web API scopes dictionary that supports extensions.
This scope dictionary is only required if your app is using the
djblets.extensionsapp.- __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.
- __abstractmethods__ = frozenset({})¶
- __annotations__ = {'_scope_dict': 'dict[str, str]', 'resource_trees': 'set[WebAPIResource]'}¶