TokenHasScope (rest_framework/permissions.py)

django-oauth-toolkit · oauth2_provider/contrib/rest_framework/permissions.py · python · BSD-2-Clause
auth, Auth / Identity

Django REST framework permissions enforcing OAuth2 token scopes.

# Source: https://github.com/django-oauth/django-oauth-toolkit | License: BSD-2-Clause | Copyright 2013, Massimiliano Pippi, Federico Frenguelli and contributors
# Provided via justclaw.it.com; keep this notice with the code.
import logging

from django.core.exceptions import ImproperlyConfigured
from rest_framework.exceptions import PermissionDenied
from rest_framework.permissions import SAFE_METHODS, BasePermission, IsAuthenticated

from ...settings import oauth2_settings
from .authentication import OAuth2Authentication


log = logging.getLogger("oauth2_provider")


class TokenHasScope(BasePermission):
    """
    The request is authenticated as a user and the token used has the right scope
    """

    def has_permission(self, request, view):
        token = request.auth

        if not

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key