Skip to content

Instantly share code, notes, and snippets.

@crooksey
Last active July 20, 2017 13:32
Show Gist options
  • Save crooksey/9d8298de88c388d49309ba557aa69f87 to your computer and use it in GitHub Desktop.
Save crooksey/9d8298de88c388d49309ba557aa69f87 to your computer and use it in GitHub Desktop.
def add_role_principals(userid, request):
return request.jwt_claims.get('roles', [])
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
config = Configurator(settings=settings)
config.include('.cors')
config.add_cors_preflight_handler()
# Enable JWT - JSON Web Token based authentication
config.set_root_factory(RootACL)
config.set_authorization_policy(ACLAuthorizationPolicy())
config.include('pyramid_jwt')
config.set_jwt_authentication_policy('secret200', auth_type="Bearer",
callback=add_role_principals)
# configure custom JSON renderers
json_renderer = JSON()
json_renderer.add_adapter(datetime.date, datetime_adapter)
json_renderer.add_adapter(Decimal, decimal_adapter)
config.add_renderer('json_custom', json_renderer)
# Customer Info JSON
config.add_route('get_customer_name', '/customerinfo/name.json')
config.add_route('login', '/user/login.json')
config.scan()
return config.make_wsgi_app()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment