flask_oauthlib/provider/oauth1.py
def require_oauth(self, *realms, **kwargs):
        """Protect resource with specified scopes."""
        def wrapper(f):
            @wraps(f)
            def decorated(*args, **kwargs):
                for func in self._before_request_funcs:
                    func()

                if hasattr(request, 'oauth') and request.oauth:
                    return f(*args, **kwargs)

                server = self.server
                uri, http_method, body, headers = extract_params()
                try:
                    valid, req = server.validate_protected_resource_request(
                        uri, http_method, body, headers, realms
                    )
                except Exception as e:
                    log.warn('Exception: %r', e)
                    e.urlencoded = urlencode([('error', 'unknown')])
                    e.status_code = 400
                    return _error_response(e)
                for func in self._after_request_funcs:
                    valid, req = func(valid, req)

                if not valid:
                    return abort(401)
                # alias user for convenience
                req.user = req.access_token.user
                request.oauth = req
                return f(*args, **kwargs)
            return decorated
        return wrapper
def require_oauth(self, *realms, **kwargs):
        """Protect resource with specified scopes."""
        def wrapper(f):
            @wraps(f)
            def decorated(*args, **kwargs):
                for func in self._before_request_funcs:
                    func()

                if hasattr(request, 'oauth') and request.oauth:
                    return f(*args, **kwargs)

                server = self.server
                uri, http_method, body, headers = extract_params()
                try:
                    valid, req = server.validate_protected_resource_request(
                        uri, http_method, body, headers, realms
                    )
                except Exception as e:
                    log.warn('Exception: %r', e)
                    e.urlencoded = urlencode([('error', 'unknown')])
                    e.status_code = 400
                    return _error_response(e)
                for func in self._after_request_funcs:
                    valid, req = func(valid, req)

                if not valid:
                    return abort(401)
                # alias user for convenience
                req.user = req.access_token.user
                request.oauth = req
                return f(*args, **kwargs)
            return decorated
        return wrapper
def require_oauth ( self , * realms , * * kwargs ) : def wrapper ( f ) : @ wraps ( f ) def decorated ( * args , * * kwargs ) : for func in self . _before_request_funcs : func ( ) if hasattr ( request , 'oauth' ) and request . oauth : return f ( * args , * * kwargs ) server = self . server uri , http_method , body , headers = extract_params ( ) try : valid , req = server . validate_protected_resource_request ( uri , http_method , body , headers , realms ) except Exception as e : log . warn ( 'Exception: %r' , e ) e . urlencoded = urlencode ( [ ( 'error' , 'unknown' ) ] ) e . status_code = 400 return _error_response ( e ) for func in self . _after_request_funcs : valid , req = func ( valid , req ) if not valid : return abort ( 401 ) # alias user for convenience req . user = req . access_token . user request . oauth = req return f ( * args , * * kwargs ) return decorated return wrapper
Protect resource with specified scopes.
Protect resource with specified scopes .