Package: pyramid_google_login
Pyramid authentication policy for Google login (OAuth2 server-side flow)This extension doesn’t configure any authentication policy. You are responsible
of setting the proper security configuration in your Pyramid application. When
authenticated by Google, this extension calls the methodpyramid.security.rememberand assume the authentication policy will
remember the user identity.PyPI:https://pypi.python.org/pypi/pyramid_google_loginCode:https://github.com/ludia/pyramid_google_loginTests:InstallationInstall using setuptools, e.g. (within a virtualenv):$ pip install pyramid_google_loginSetup: ApplicationOncepyramid_google_loginis installed, you must use theconfig.includemechanism to include it into your Pyramid project’s configuration.  In your
Pyramid project’s__init__.py:config=Configurator(.....)config.include('pyramid_google_login')Alternately you can use thepyramid.includesconfiguration value in your.inifile:[app:myapp]pyramid.includes=pyramid_google_loginSetup: settingsMandatory settings:security.google_login.client_id=xxxxxxx.apps.googleusercontent.comsecurity.google_login.client_secret=xxxxxxxxxxxxxxxxxxxxxxxxxOptional settings:# List of Google scopes (``email`` is automatically included)security.google_login.scopes=email# Set the access type to ``offline`` to get a refresh_token (default: online)security.google_login.access_type=online# Field used to extract the userid (generally ``email`` or ``id``)security.google_login.user_id_field=email# Restrict authentication to a Google Apps domainsecurity.google_login.hosted_domain=example.net# Redirect destination for logged in user.security.google_login.landing_url=/security.google_login.landing_route=my_frontend_routesecurity.google_login.landing_route=mymodule:static/# Add a banner on the sign in pagesecurity.google_login.signin_banner=Welcome on Project Euler# Add an advice on the sign in pagesecurity.google_login.signin_advice=Ask Dilbert for accessSetup: Google projectCreate a project onhttps://console.developers.google.comCreate a OAuth Client IDChoose aWeb Applicationapplication typeAdd all variants of your host in Javascript OriginsSecure and non secure url are differentiatedOptionally include your development host withhttp://localhost:6543rather than anhttp://127.0.0.1:6543(it would be refused)Notes:NoPermissionsare needed bypyramid_google_loginitself.Client ID parameters are heavily cached. In development, re-creating a client
id is often the best idea.General UsageWhen a user must be authenticated by Google, he must be sent to theauth_signinroute url. The helper methodpyramid_google_login.redirect_to_signinredirect the user to the sign in
page. This helper is handy to specify the next url and an optional message.@forbidden_view_config()defunauthenticated(context,request):returnredirect_to_signin(request,url=request.path_qs)Once the user is authenticated, theUserLoggedInpyramid event is
broadcasted. The application can perform subsequent validations, create the
user profile or update it.After that, thepyramid.security.rememberhelper is called.Then, the user will be redirected to an url specified by:query parameter (signin page):urlsetting:security.google_login.landing_urlfallback:/When a user must be logged out, he must be directed on theauth_logoutroute url. Once logged out, he will be redirected back to the sign in page.Offline UsageIf you want to call the Google APIs on behalf of the user, you must store the
OAuth2 tokens provided in the UserLoggedIn event. Theaccess_tokenis
usable for anexpires_inperiod. Then therefresh_tokenmust be used to
refresh theaccess_token. Thisrefresh_tokenis valide until the user
revoke the application permissions.By default, the only scope requested isemailto identify the user. To call
other Google APIs, you must add the related scopes as this:[app:myapp]security.google_login.scopes=emailhttps://www.googleapis.com/auth/admin.directory.user.readonlyEventsUserLoggedInThe user has logged in by Google.Properties:useridoauth2_tokenaccess_tokenexpires_inrefresh_tokenuser_infoGoogle user_info properties…UserLoggedOutThe user has logged out.Properties:useridDevelopmentThis project supports Dad (https://github.com/pior/dad).Running tests:$ pip install -r requirements.txt
$ nosetestsRunning pylama (linters):$ pylamaCreate a new release:$ dad release 1.0