Skip to content

Commit

Permalink
Import SAFE_METHODS from rest_framework.permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
jleclanche committed Sep 15, 2017
1 parent 2cd1f0d commit 50e4df7
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions oauth2_provider/contrib/rest_framework/permissions.py
@@ -1,16 +1,14 @@
import logging

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

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


log = logging.getLogger("oauth2_provider")

SAFE_HTTP_METHODS = ["GET", "HEAD", "OPTIONS"]


class TokenHasScope(BasePermission):
"""
Expand Down Expand Up @@ -54,7 +52,7 @@ def get_scopes(self, request, view):
required_scopes = []

# TODO: code duplication!! see dispatch in ReadWriteScopedResourceMixin
if request.method.upper() in SAFE_HTTP_METHODS:
if request.method.upper() in SAFE_METHODS:
read_write_scope = oauth2_settings.READ_SCOPE
else:
read_write_scope = oauth2_settings.WRITE_SCOPE
Expand All @@ -75,7 +73,7 @@ def get_scopes(self, request, view):
except ImproperlyConfigured:
view_scopes = []

if request.method.upper() in SAFE_HTTP_METHODS:
if request.method.upper() in SAFE_METHODS:
scope_type = oauth2_settings.READ_SCOPE
else:
scope_type = oauth2_settings.WRITE_SCOPE
Expand Down

0 comments on commit 50e4df7

Please sign in to comment.