本文整理汇总了Python中pyramid.config.Configurator.add_openid_login方法的典型用法代码示例。如果您正苦于以下问题:Python Configurator.add_openid_login方法的具体用法?Python Configurator.add_openid_login怎么用?Python Configurator.add_openid_login使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyramid.config.Configurator
的用法示例。
在下文中一共展示了Configurator.add_openid_login方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_openid_login [as 别名]
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
session_factory = UnencryptedCookieSessionFactoryConfig(
'meepown3d'
)
engine = engine_from_config(settings, 'sqlalchemy.')
DBSession.configure(bind=engine)
Base.metadata.bind = engine
config = Configurator(settings=settings)
config.set_session_factory(session_factory)
config.add_route('index', r'/')
config.add_route('items', r'/items')
config.add_route('heroes', r'/heroes')
config.add_route('hero_details', r'/heroes/{name:[\w\-]+}')
config.add_route('recent_matches', r'/matches')
config.add_route('match_details', r'/matches/{id:\d+}')
config.add_route('players_index', r'/players')
config.add_route('player_details', r'/players/{id:\d+}')
config.add_route('trends_index', r'/trends')
config.include('velruse.providers.openid')
config.add_openid_login('ohnozombi.es')
register_steam_provider(config)
config.scan()
return config.make_wsgi_app()
示例2: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_openid_login [as 别名]
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
config = Configurator(root_factory=Root, settings=settings)
config.include(pyramid_beaker)
config.include("pyramid_mailer")
config.include("velruse.providers.openid")
config.add_openid_login(realm="http://mobyle2:6543")
authentication_policy = AuthTktAuthenticationPolicy("seekrit")
authorization_policy = ACLAuthorizationPolicy()
config.set_authentication_policy(authentication_policy)
config.set_authorization_policy(authorization_policy)
db_uri = settings["db_uri"]
conn = pymongo.Connection(db_uri, safe=True)
config.registry.settings["db_conn"] = conn
# initialize database when empty:
db = conn[config.registry.settings["db_name"]]
if db.users.find().count() == 0:
pwd = sha1("%s" % randint(1, 1e99)).hexdigest()
print "root user created with password: ", pwd
user = {
"login": "root",
"admin": True,
"password": pwd,
"email": settings["root_email"],
"firstname": "root",
"lastname": "root",
}
add_user(db, user)
# end initialization
config.add_subscriber(add_mongo_db, NewRequest)
config.add_subscriber(before_render, BeforeRender)
config.add_route("main", "/")
config.add_route("onlyauthenticated", "/onlyauthenticated")
config.add_route("login", "/login")
config.add_route("logout", "/logout")
config.add_route("program_list", "/programs/list")
# config.add_route('velruse_endpoint', '/loginendpoint')
# config.add_route('logout', "/logout")
config.add_static_view("static", "mobyle:static", cache_max_age=3600)
config.scan()
return config.make_wsgi_app()
示例3: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_openid_login [as 别名]
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
engine = engine_from_config(settings, 'sqlalchemy.')
DBSession.configure(bind=engine)
session_factory = session_factory_from_settings(settings)
config = Configurator(settings=settings)
config.set_session_factory(session_factory)
config.include('velruse.providers.openid')
config.add_openid_login(
realm='localhost:6543')
config.add_static_view('static', 'static', cache_max_age=3600)
config.add_route('index', '/')
config.add_route('login', '/login')
config.add_route('logout', '/logout')
config.add_route('prefs', '/prefs')
config.scan()
return config.make_wsgi_app()
示例4: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_openid_login [as 别名]
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
cache = dogpile.cache.make_region(
key_mangler=dogpile.cache.util.sha1_mangle_key)
tahrir_api.model.Person.avatar_url = make_avatar_method(cache)
tahrir_api.model.Person.email_md5 = property(
lambda self: hashlib.md5(self.email).hexdigest())
tahrir_api.model.Person.email_sha1 = property(
lambda self: hashlib.sha1(self.email).hexdigest())
identifier = settings.get('tahrir.openid_identifier')
tahrir_api.model.Person.openid_identifier =\
make_openid_identifier_property(identifier)
tahrir_api.model.Person.created_on_rel =\
make_relative_time_property('created_on')
tahrir_api.model.Assertion.created_on_rel =\
make_relative_time_property('created_on')
tahrir_api.model.Assertion.issued_on_rel =\
make_relative_time_property('issued_on')
session_cls = scoped_session(sessionmaker(
extension=ZopeTransactionExtension(),
bind=create_engine(settings['sqlalchemy.url']),
))
def get_db(request):
""" Database retrieval function to be added to the request for
calling anywhere.
"""
session = session_cls()
return TahrirDatabase(session=session, autocommit=False,
notification_callback=notifications.callback)
required_keys = [
'tahrir.pngs.uri',
'tahrir.admin',
'tahrir.title',
'tahrir.base_url',
]
# validate the config
for key in required_keys:
if key not in settings:
raise ValueError("%s required in settings." % key)
# Make data dir if it doesn't already exist.
settings['tahrir.pngs.uri'] = os.path.abspath(settings['tahrir.pngs.uri'])
if not os.path.exists(settings['tahrir.pngs.uri']):
os.makedirs(settings['tahrir.pngs.uri'])
# Load secret stuff from secret.ini.
try:
default_path = os.path.abspath("secret.ini")
secret_path = settings.get('secret_config_path', default_path)
# TODO: There is a better way to log this message than print.
print "Reading secrets from %r" % secret_path
parser = ConfigParser.ConfigParser()
parser.read(secret_path)
secret_config = dict(parser.items("tahrir"))
settings.update(secret_config)
except Exception as e:
# TODO: There is a better way to log this message than print.
print 'Failed to load secret.ini. Reason: %r' % str(e)
authn_policy = AuthTktAuthenticationPolicy(
secret=settings['authnsecret'],
callback=groupfinder, # groupfinder callback checks for admin privs
hashalg='sha512', # because md5 is deprecated
secure=asbool(settings['tahrir.secure_cookies']),
)
authz_policy = ACLAuthorizationPolicy()
session_factory = UnencryptedCookieSessionFactoryConfig(
settings['session.secret'])
# Configure our cache that we instantiated earlier.
cache.configure_from_config(settings, 'dogpile.cache.')
config = Configurator(
settings=settings,
root_factory=get_root,
session_factory=session_factory,
authentication_policy=authn_policy,
authorization_policy=authz_policy)
config.include('velruse.providers.openid')
config.add_openid_login(realm=settings.get('tahrir.openid_realm'))
config.add_request_method(get_db, 'db', reify=True)
config.add_static_view(
'static',
settings.get('tahrir.theme_name', 'tahrir') + ':static',
cache_max_age=3600,
)
config.add_static_view(
'pngs',
#.........这里部分代码省略.........
示例5: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_openid_login [as 别名]
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
cache = dogpile.cache.make_region(key_mangler=dogpile.cache.util.sha1_mangle_key)
tahrir_api.model.Person.avatar_url = make_avatar_method(cache)
identifier = settings.get("tahrir.openid_identifier")
tahrir_api.model.Person.openid_identifier = make_openid_identifier_property(identifier)
tahrir_api.model.Person.created_on_rel = make_relative_time_property("created_on")
tahrir_api.model.Assertion.created_on_rel = make_relative_time_property("created_on")
tahrir_api.model.Assertion.issued_on_rel = make_relative_time_property("issued_on")
session_cls = scoped_session(
sessionmaker(extension=ZopeTransactionExtension(), bind=create_engine(settings["sqlalchemy.url"]))
)
def get_db(request):
""" Database retrieval function to be added to the request for
calling anywhere.
"""
session = session_cls()
return TahrirDatabase(session=session, autocommit=False)
required_keys = ["tahrir.pngs.uri", "tahrir.admin", "tahrir.title", "tahrir.base_url"]
# validate the config
for key in required_keys:
if key not in settings:
raise ValueError("%s required in settings." % key)
# Make data dir if it doesn't already exist.
settings["tahrir.pngs.uri"] = os.path.abspath(settings["tahrir.pngs.uri"])
if not os.path.exists(settings["tahrir.pngs.uri"]):
os.makedirs(settings["tahrir.pngs.uri"])
# Load secret stuff from secret.ini.
try:
default_path = os.path.abspath("secret.ini")
secret_path = settings.get("secret_config_path", default_path)
# TODO: There is a better way to log this message than print.
print "Reading secrets from %r" % secret_path
parser = ConfigParser.ConfigParser()
parser.read(secret_path)
secret_config = dict(parser.items("tahrir"))
settings.update(secret_config)
except Exception as e:
# TODO: There is a better way to log this message than print.
print "Failed to load secret.ini. Reason: %r" % str(e)
authn_policy = AuthTktAuthenticationPolicy(
secret=settings["authnsecret"],
callback=groupfinder, # groupfinder callback checks for admin privs
hashalg="sha512", # because md5 is deprecated
secure=asbool(settings["tahrir.secure_cookies"]),
)
authz_policy = ACLAuthorizationPolicy()
session_factory = UnencryptedCookieSessionFactoryConfig(settings["session.secret"])
# Configure our cache that we instantiated earlier.
cache.configure_from_config(settings, "dogpile.cache.")
config = Configurator(
settings=settings,
root_factory=get_root,
session_factory=session_factory,
authentication_policy=authn_policy,
authorization_policy=authz_policy,
)
config.include("velruse.providers.openid")
config.add_openid_login(realm=settings.get("tahrir.openid_realm"))
config.add_request_method(get_db, "db", reify=True)
config.add_static_view("static", settings.get("tahrir.static.uri", "static"), cache_max_age=3600)
config.add_static_view("pngs", settings["tahrir.pngs.uri"], cache_max_age=3600)
config.add_route("home", "/")
config.add_route("admin", "/admin")
config.add_route("qrcode", "/qrcode")
config.add_route("badge", "/badge/{id}")
config.add_route("badge_json", "/badge/{id}/json")
config.add_route("builder", "/builder")
config.add_route("explore", "/explore")
config.add_route("explore_badges", "/explore/badges")
config.add_route("leaderboard", "/leaderboard")
config.add_route("leaderboard_json", "/leaderboard/json")
config.add_route("rank_json", "/leaderboard/{id}/json")
config.add_route("tags", "/tags/{tags}/{match}")
config.add_route("user", "/user/{id}")
config.add_route("user_json", "/user/{id}/json")
config.add_route("login", "/login")
config.add_route("logout", "/logout")
# Used to grab a "was awarded" html snippet asynchronously
config.add_route("assertion_widget", "/_w/assertion/{person}/{badge}")
config.scan()
#.........这里部分代码省略.........
示例6: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_openid_login [as 别名]
def main(global_conf, **settings):
session_factory = UnencryptedCookieSessionFactoryConfig('seekrit')
providers = settings.get('login_providers', '')
providers = filter(None, [p.strip()
for line in providers.splitlines()
for p in line.split(', ')])
settings['login_providers'] = providers
config = Configurator(settings=settings)
config.set_session_factory(session_factory)
if 'facebook' in providers:
config.include('velruse.providers.facebook')
config.add_facebook_login(
settings['velruse.facebook.app_id'],
settings['velruse.facebook.app_secret'],
)
if 'github' in providers:
config.include('velruse.providers.github')
config.add_github_login(
settings['velruse.github.app_id'],
settings['velruse.github.app_secret'],
)
if 'twitter' in providers:
config.include('velruse.providers.twitter')
config.add_twitter_login(
settings['velruse.twitter.consumer_key'],
settings['velruse.twitter.consumer_secret'],
)
if 'live' in providers:
config.include('velruse.providers.live')
config.add_live_login(
settings['velruse.live.client_id'],
settings['velruse.live.client_secret'],
)
if 'bitbucket' in providers:
config.include('velruse.providers.bitbucket')
config.add_bitbucket_login(
settings['velruse.bitbucket.consumer_key'],
settings['velruse.bitbucket.consumer_secret'],
)
if 'google_hybrid' in providers:
config.include('velruse.providers.google_hybrid')
config.add_google_hybrid_login(
realm=settings['velruse.google_hybrid.realm'],
consumer_key=settings['velruse.google_hybrid.consumer_key'],
consumer_secret=settings['velruse.google_hybrid.consumer_secret'],
scope=settings.get('velruse.google_hybrid.scope'),
login_path='/login/google_hybrid',
callback_path='/login/google_hybrid/callback',
name='google_hybrid',
)
if 'google_oauth2' in providers:
config.include('velruse.providers.google_oauth2')
config.add_google_oauth2_login(
consumer_key=settings['velruse.google_oauth2.consumer_key'],
consumer_secret=settings['velruse.google_oauth2.consumer_secret'],
scope=settings.get('velruse.google_oauth2.scope'),
login_path='/login/google_oauth2',
callback_path='/login/google_oauth2/callback',
name='google_oauth2',
)
if 'openid' in providers:
config.include('velruse.providers.openid')
config.add_openid_login(
realm=settings['velruse.openid.realm'],
)
if 'yahoo' in providers:
config.include('velruse.providers.yahoo')
config.add_yahoo_login(
realm=settings['velruse.yahoo.realm'],
consumer_key=settings['velruse.yahoo.consumer_key'],
consumer_secret=settings['velruse.yahoo.consumer_secret'],
)
if 'linkedin' in providers:
config.include('velruse.providers.linkedin')
config.add_linkedin_login(
settings['velruse.linkedin.consumer_key'],
settings['velruse.linkedin.consumer_secret'],
)
if 'linkedin_oauth2' in providers:
config.include('velruse.providers.linkedin_oauth2')
config.add_linkedin_oauth2_login(
settings['velruse.linkedin.consumer_key'],
settings['velruse.linkedin.consumer_secret'],
)
config.scan(__name__)
return config.make_wsgi_app()
示例7: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_openid_login [as 别名]
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
required_keys = [
'tahrir.salt',
'tahrir.pngs.uri',
'tahrir.admin',
'tahrir.title',
'tahrir.base_url',
]
# validate the config
for key in required_keys:
if key not in settings:
raise ValueError("%s required in settings." % key)
# Make data dir if it doesn't already exist.
settings['tahrir.pngs.uri'] = os.path.abspath(settings['tahrir.pngs.uri'])
if not os.path.exists(settings['tahrir.pngs.uri']):
os.makedirs(settings['tahrir.pngs.uri'])
# Set that directory on the filefield widget.
SavingFileField.png_dir = settings['tahrir.pngs.uri']
# start setting things up
engine = engine_from_config(settings, 'sqlalchemy.')
DBSession.configure(bind=engine)
authn_policy = AuthTktAuthenticationPolicy(
secret='verysecret',
)
authz_policy = ACLAuthorizationPolicy()
session_factory = UnencryptedCookieSessionFactoryConfig(
settings['session.secret'])
config = Configurator(
settings=settings,
root_factory=get_root,
session_factory=session_factory)
config.include('velruse.providers.openid')
config.add_openid_login(
realm="http://localhost:6543/"
)
config.set_authentication_policy(authn_policy)
config.set_authorization_policy(authz_policy)
config.add_static_view(
'static',
settings.get('tahrir.static.uri', 'static'),
cache_max_age=3600,
)
config.add_static_view(
'pngs',
settings['tahrir.pngs.uri'],
cache_max_age=3600,
)
config.add_route('home', '/')
config.add_route('admin', '/admin')
config.add_route('login', '/login')
config.add_route('logout', '/logout')
config.scan()
return config.make_wsgi_app()