def before_request(): # In a real app, the current user and consumer would be determined by # a lookup in either the session or the request headers, as described # in the Annotator authentication documentation[1]. # # [1]: https://github.com/okfn/annotator/wiki/Authentication g.user = MockUser('alice') # By default, this test application won't do full-on authentication # tests. Set AUTH_ON to True in the config file to enable (limited) # authentication testing. if current_app.config['AUTH_ON']: # g.auth = auth.Authenticator(lambda x: MockConsumer('annotateit')) consumer_obj = Consumer('yourconsumerkey') consumer_obj.secret = '6E1C924B-C03B-4F7F-0000-B72EE2338B39' consumer_obj.ttl = auth.DEFAULT_TTL g.auth = auth.Authenticator(lambda x: consumer_obj) else: g.auth = MockAuthenticator() # Similarly, this test application won't prevent you from modifying # annotations you don't own, deleting annotations you're disallowed # from deleting, etc. Set AUTHZ_ON to True in the config file to # enable authorization testing. if current_app.config['AUTHZ_ON']: g.authorize = authz.authorize print("[run.py,before_request], AUTHZ_ON") else: g.authorize = mock_authorizer print("[run.py,before_request], AUTHZ_OFF")
def before_request(): g.debug = current_app.debug # User from session username = session.get('user') g.user = User.fetch(username) g.auth = auth.Authenticator(Consumer.fetch) g.authorize = authz.authorize g.after_annotation_create = _add_annotation_link g.before_annotation_update = _add_annotation_link
def includeme(config): """Include the annotator-store API backend. Example INI file: [app:h] consumer_key: primary_consumer consumer_secret: 00000000-0000-0000-0000-000000000000 """ settings = config.get_settings() if not settings.has_key('h.consumer_key'): raise KeyError('h.consumer_key') if not settings.has_key('h.consumer_secret'): raise KeyError('h.consumer_secret') # Create the annotator-store app app = Flask(__name__) app.register_blueprint(store.store) # Set up the models es.init_app(app) with app.test_request_context(): try: Annotation.create_all() except: Annotation.update_settings() Annotation.create_all() # Configure authentication (ours) and authorization (store) authenticator = auth.Authenticator(consumer_fetcher) def before_request(): g.auth = authenticator g.authorize = authz.authorize app.before_request(before_request) # Configure the API views config.add_view(wsgiapp2(app), route_name='api') config.add_view(token, route_name='token', permission='authenticated') config.add_view(users, route_name='users', request_method='GET', permission='authenticated', renderer='json')
def includeme(config): """Include the annotator-store API backend. Example INI file: [app:h] api.key: 00000000-0000-0000-0000-000000000000 """ app = Flask('annotator') # Create the annotator-store app app.register_blueprint(store.store) # and register the store api. # Set up the models settings = config.get_settings() if 'es.host' in settings: app.config['ELASTICSEARCH_HOST'] = settings['es.host'] if 'es.index' in settings: app.config['ELASTICSEARCH_INDEX'] = settings['es.index'] es.init_app(app) with app.test_request_context(): try: Annotation.create_all() except: Annotation.update_settings() Annotation.create_all() # Configure authentication (ours) and authorization (store) authenticator = auth.Authenticator(models.Consumer.get_by_key) def before_request(): g.auth = authenticator g.authorize = authz.authorize app.before_request(before_request) # Configure the API view -- version 1 is just an annotator.store proxy config.add_view(wsgiapp2(app), context='h.resources.APIFactory', name='v1') config.add_view(wsgiapp2(app), context='h.resources.APIFactory', name='current') # And pick up the token view config.scan(__name__)
def before_request(): # In a real app, the current user and consumer would be determined by # a lookup in either the session or the request headers, as described # in the Annotator authentication documentation[1]. # # [1]: https://github.com/okfn/annotator/wiki/Authentication g.user = MockUser('anonymous') # By default, this test application won't do full-on authentication # tests. Set AUTH_ON to True in the config file to enable (limited) # authentication testing. if current_app.config['AUTH_ON']: g.auth = auth.Authenticator(lambda x: MockConsumer('annotateit')) else: g.auth = MockAuthenticator() # Similarly, this test application won't prevent you from modifying # annotations you don't own, deleting annotations you're disallowed # from deleting, etc. Set AUTHZ_ON to True in the config file to # enable authorization testing. if current_app.config['AUTHZ_ON']: g.authorize = authz.authorize else: g.authorize = mock_authorizer
def before_request(): flask.g.auth = auth.Authenticator(models.Consumer.get_by_key) flask.g.authorize = authorize flask.g.before_annotation_update = anonymize_deletes
def before_request(): g.auth = auth.Authenticator(MockConsumer) g.authorize = authz.authorize
def setup(self): self.consumer = MockConsumer() fetcher = lambda x: self.consumer self.auth = auth.Authenticator(fetcher)