示例#1
0
    def OAuthCheckAccessResource(cls):
        from indico.modules.oauth.db import ConsumerHolder, AccessTokenHolder, OAuthServer

        oauth_request = oauth.Request.from_request(request.method, request.base_url, request.headers,
                                                   parameters=create_flat_args())
        Logger.get('oauth.resource').info(oauth_request)
        try:
            now = nowutc()
            consumer_key = oauth_request.get_parameter('oauth_consumer_key')
            if not ConsumerHolder().hasKey(consumer_key):
                raise OAuthError('Invalid Consumer Key', 401)
            consumer = ConsumerHolder().getById(consumer_key)
            token = oauth_request.get_parameter('oauth_token')
            if not token or not AccessTokenHolder().hasKey(token):
                raise OAuthError('Invalid Token', 401)
            access_token = AccessTokenHolder().getById(token)
            oauth_consumer = oauth.Consumer(consumer.getId(), consumer.getSecret())
            OAuthServer.getInstance().verify_request(oauth_request, oauth_consumer, access_token.getToken())
            if access_token.getConsumer().getId() != oauth_consumer.key:
                raise OAuthError('Invalid Consumer Key', 401)
            elif (now - access_token.getTimestamp()) > timedelta(seconds=Config.getInstance().getOAuthAccessTokenTTL()):
                raise OAuthError('Expired Token', 401)
            return access_token
        except oauth.Error, e:
            if e.message.startswith("Invalid Signature"):
                raise OAuthError("Invalid Signature", 401)
            else:
                raise OAuthError(e.message, 400)
示例#2
0
    def OAuthCheckAccessResource(cls, req, query_string):
        from indico.modules.oauth.db import  ConsumerHolder, AccessTokenHolder, OAuthServer

        oauth_request = oauth.Request.from_request(req.get_method(),req.construct_url(req.get_uri()), headers=req.headers_in, query_string=urlencode(query_string))
        Logger.get('oauth.resource').info(oauth_request)
        try:
            now = time.time()
            consumer_key = oauth_request.get_parameter('oauth_consumer_key')
            if not ConsumerHolder().hasKey(consumer_key):
                raise OAuthError('Invalid Consumer Key' , apache.HTTP_UNAUTHORIZED)
            consumer = ConsumerHolder().getById(consumer_key)
            token = oauth_request.get_parameter('oauth_token')
            if not token or not AccessTokenHolder().hasKey(token):
                raise OAuthError('Invalid Token', apache.HTTP_UNAUTHORIZED)
            access_token = AccessTokenHolder().getById(token)
            oauth_consumer = oauth.Consumer(consumer.getId(), consumer.getSecret())
            OAuthServer.getInstance().verify_request(oauth_request, oauth_consumer, access_token.getToken())
            if access_token.getConsumer().getId() != oauth_consumer.key:
                raise OAuthError('Invalid Consumer Key' , apache.HTTP_UNAUTHORIZED)
            elif (now - access_token.getTimestamp()) > Config.getInstance().getOAuthAccessTokenTTL():
                raise OAuthError('Expired Token', apache.HTTP_UNAUTHORIZED)
            return access_token
        except oauth.Error, e:
            if e.message.startswith("Invalid Signature"):
                raise OAuthError("Invalid Signature", apache.HTTP_UNAUTHORIZED)
            else:
                raise OAuthError(e.message, apache.HTTP_BAD_REQUEST)
示例#3
0
    def OAuthCheckAccessResource(cls):
        from indico.modules.oauth.db import ConsumerHolder, AccessTokenHolder, OAuthServer

        oauth_request = oauth.Request.from_request(
            request.method,
            request.base_url,
            request.headers,
            parameters=create_flat_args())
        Logger.get('oauth.resource').info(oauth_request)
        try:
            now = nowutc()
            consumer_key = oauth_request.get_parameter('oauth_consumer_key')
            if not ConsumerHolder().hasKey(consumer_key):
                raise OAuthError('Invalid Consumer Key', 401)
            consumer = ConsumerHolder().getById(consumer_key)
            token = oauth_request.get_parameter('oauth_token')
            if not token or not AccessTokenHolder().hasKey(token):
                raise OAuthError('Invalid Token', 401)
            access_token = AccessTokenHolder().getById(token)
            oauth_consumer = oauth.Consumer(consumer.getId(),
                                            consumer.getSecret())
            OAuthServer.getInstance().verify_request(oauth_request,
                                                     oauth_consumer,
                                                     access_token.getToken())
            if access_token.getConsumer().getId() != oauth_consumer.key:
                raise OAuthError('Invalid Consumer Key', 401)
            elif (now - access_token.getTimestamp()) > timedelta(
                    seconds=Config.getInstance().getOAuthAccessTokenTTL()):
                raise OAuthError('Expired Token', 401)
            return access_token
        except oauth.Error, e:
            if e.message.startswith("Invalid Signature"):
                raise OAuthError("Invalid Signature", 401)
            else:
                raise OAuthError(e.message, 400)
示例#4
0
 def _checkParams(self, params):
     try:
         RHOAuth._checkParams(self, params)
         consumer_key = self._oauth_request.get_parameter('oauth_consumer_key')
         Logger.get('oauth.request_token').info(consumer_key)
         if not ConsumerHolder().hasKey(consumer_key):
             raise OAuthError("Invalid Consumer Key", 401)
         self._consumer = ConsumerHolder().getById(consumer_key)
         #Logger.get('oauth.request_token').info(consumer.getSecret())
         oauth_consumer = oauth.Consumer(self._consumer.getId(), self._consumer.getSecret())
         OAuthServer.getInstance().verify_request(self._oauth_request, oauth_consumer, None)
     except oauth.Error, err:
         raise OAuthError(err.message, 401)
示例#5
0
 def _checkParams(self, params):
     RHOAuth._checkParams(self, params)
     try:
         request_token_key = self._oauth_request.get_parameter('oauth_token')
         self.verifier = self._oauth_request.get_parameter('oauth_verifier')
         if not RequestTokenHolder().hasKey(request_token_key):
             raise OAuthError("Invalid Token", 401)
         self._request_token = RequestTokenHolder().getById(request_token_key)
         if self._request_token.getToken().verifier != self.verifier:
             raise OAuthError("Invalid Token", 401)
         if not ConsumerHolder().hasKey(self._request_token.getConsumer().getId()):
             raise OAuthError("Invalid Consumer Key", 401)
         consumer = oauth.Consumer(self._request_token.getConsumer().getId(), self._request_token.getConsumer().getSecret())
         OAuthServer.getInstance().verify_request(self._oauth_request, consumer, self._request_token.getToken())
     except oauth.Error, err:
         raise OAuthError(err.message, 401)