Example #1
0
 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()
Example #2
0
 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()
Example #3
0
 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()
Example #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)
Example #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