예제 #1
0
파일: utils.py 프로젝트: mhellmic/b2share
 def remove_api_key(self):
     if self.apikey:
         from invenio.modules.apikeys.models import WebAPIKey
         k = WebAPIKey.filter_by(id=self.apikey).first()
         if k:
             db.session.delete(k)
             db.session.commit()
예제 #2
0
파일: utils.py 프로젝트: chokribr/invenio-1
 def remove_api_key(self):
     """Remove api key."""
     from invenio.ext.sqlalchemy import db
     if self.apikey:
         from invenio.modules.apikeys.models import WebAPIKey
         k = WebAPIKey.filter_by(id=self.apikey).first()
         if k:
             db.session.delete(k)
             db.session.commit()
예제 #3
0
파일: utils.py 프로젝트: SCOAP3/invenio
 def remove_api_key(self):
     """Remove api key."""
     from invenio.ext.sqlalchemy import db
     if self.apikey:
         from invenio.modules.apikeys.models import WebAPIKey
         k = WebAPIKey.filter_by(id=self.apikey).first()
         if k:
             db.session.delete(k)
             db.session.commit()
예제 #4
0
        def decorated(*args, **kwargs):
            if 'apikey' in request.values:
                # API key authentication
                warnings.warn(
                    "API keys will be superseded by OAuth personal access "
                    "tokens",
                    PendingDeprecationWarning
                )

                from invenio.modules.apikeys.models import WebAPIKey
                from invenio.ext.login import login_user

                user_id = WebAPIKey.acc_get_uid_from_request()
                if user_id == -1:
                    restful.abort(401)

                login_user(user_id)
                resp = f(None, *args, **kwargs)
                session.clear()
                return resp
            else:
                # OAuth 2.0 Authentication
                for func in oauth2._before_request_funcs:
                    func()

                server = oauth2.server
                uri, http_method, body, headers = extract_params()
                valid, req = server.verify_request(
                    uri, http_method, body, headers, scopes
                )

                for func in oauth2._after_request_funcs:
                    valid, req = func(valid, req)

                if not valid:
                    return restful.abort(
                        401,
                        message="Unauthorized",
                        status=401,
                    )

                resp = f(req, *args, **kwargs)
                session.clear()
                return resp
            restful.abort(401)
예제 #5
0
        def decorated(*args, **kwargs):
            if 'apikey' in request.values:
                # API key authentication
                warnings.warn(
                    "API keys will be superseded by OAuth personal access "
                    "tokens",
                    PendingDeprecationWarning
                )

                from invenio.modules.apikeys.models import WebAPIKey
                from invenio.ext.login import login_user

                user_id = WebAPIKey.acc_get_uid_from_request()
                if user_id == -1:
                    restful.abort(401)

                login_user(user_id)
                resp = f(None, *args, **kwargs)
            else:
                # OAuth 2.0 Authentication
                resp = f_oauth_required(*args, **kwargs)
            session.clear()
            return resp