适用于TurboGears2的Google身份验证
项目描述
关于googleplusauth
googleplusauth是一个适用于TurboGears2的可插拔应用程序。
它的目的是简化在TurboGears2应用程序中实现Google身份验证和注册的过程。
安装
googleplusauth可以从PyPI或Bitbucket安装
pip install tgapp-googleplusauth
对大多数用户应该可以正常工作
插入googleplusauth
在您的应用程序 config/app_cfg.py 中导入 plug
from tgext.pluggable import plug
然后在文件 末尾 调用 plug 并传入googleplusauth
plug(base_config, 'googleplusauth')
在sql数据库上,为了创建表,您可以使用迁移(s)来运行
gearbox migrate-pluggable -c development.ini googleplusauth upgrade
或者如果您还可以删除数据库,setup-app 应该就足够了。
Googleplushaut助手
googleplusauth提供了一些助手,可以自动生成按钮和JavaScript,让您的用户使用Google登录您的应用程序
- h.googleplusauth.login_button(client_id, scope=None, data_cookiepolicy=None, img_btn_login=None, remember=None)
放置登录/注册按钮,如果用户从未使用Google登录,将自动创建新用户,否则直接登录。
参数 client_id 是您的_CLIENT_ID.apps.googleusercontent.com
参数 scope 是应用程序将请求Google的权限。默认情况下,这些权限仅包括 https://www.googleapis.com/auth/userinfo.email。更多权限请参阅: https://developers.google.com/oauthplayground/
参数 data_cookiepolicy 表示要创建登录cookie的域名。
参数 img_btn_login 表示按钮图片的URL。
参数 remember 可以用来使用过期日期而不是会话cookie来登录用户,这样会话可以比浏览器标签的生命周期更长。
这是按钮的HTML代码,如果您想自定义按钮样式
<div id="button-container"> <div id="google-login-button" style="cursor: pointer;" onclick="perform_google_login()"> <img id="img-login" src='%(img_btn_login)s' alt='Google Login' /> </div> </div>
可用的钩子
googleplusauth提供了一些钩子,这些钩子将在某些操作期间被调用,以改变应用程序的默认行为
- googleplusauth.on_registration(google_response, user) -> 当从Google注册新用户时运行
登录,允许添加或修改用户的其他数据。
- googleplusauth.on_login(google_response, user) -> 用户执行Google登录时运行
允许更新用户数据。
Google ID和头像
用户将有一个新的相关实体,称为googleplusauth。通过访问user.googleplusauth,可以访问用户user.googleplusauth.google_id和user.googleplusauth.profile_picture等更多信息。
项目详情
tgapp-googlePlusAuth-0.0.9.tar.gz的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 967aede3db44443fb378138c7b683678235a7ddaa2fc93f07a31c146cea0a53d |
|
MD5 | d0cc9b973cfd12d0cb8e891d7f26940c |
|
BLAKE2b-256 | b85db4051ce1ec2427c7a5df46f9a5f0137d041a40e74a8038f6528a9f418a9c |