跳转到主要内容

适用于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_iduser.googleplusauth.profile_picture等更多信息。

项目详情


下载文件

下载适用于您平台的文件。如果您不确定选择哪个,请了解更多关于安装包的信息。

源分布

tgapp-googlePlusAuth-0.0.9.tar.gz (13.7 kB 查看哈希值)

上传时间

由以下支持