def protected_resource(scopes=None, validator_cls=OAuth2Validator, server_cls=Server):
 _scopes = (scopes or [])
 def decorator(view_func):
  @wraps(view_func)
  def _validate(request, *args, **kwargs):
   validator = validator_cls()
   core = OAuthLibCore(server_cls(validator))
   (valid, oauthlib_req) = core.verify_request(request, scopes=_scopes)
   if valid:
    request.resource_owner = oauthlib_req.user
    return view_func(request, *args, **kwargs)
   return HttpResponseForbidden()
  return _validate
 return decorator

def protected_resource ( scopes = None , validator_cls = OAuth2Validator , server_cls = Server ) : _scopes = ( scopes or [ ] ) def decorator ( view_func ) : @ wraps ( view_func ) def _validate ( request , * args , ** kwargs ) : validator = validator_cls ( ) core = OAuthLibCore ( server_cls ( validator ) ) ( valid , oauthlib_req ) = core . verify_request ( request , scopes = _scopes ) if valid : request . resource_owner = oauthlib_req . user return view_func ( request , * args , ** kwargs ) return HttpResponseForbidden ( ) return _validate return decorator
decorator to protect views by providing oauth2 authentication out of the box .