【问题标题】:how to store google oauth token in django : Storage or database如何在 django 中存储 google oauth 令牌:存储或数据库
【发布时间】:2014-12-08 12:01:51
【问题描述】:

Google APIs python 客户端对 Django 有特殊的支持,在 Google (https://developers.google.com/api-client-library/python/guide/django) 给出的示例中,oauth2client.django_orm.Storage 类用于存储和检索 Credentials 对象。

但是,我发现很多示例(https://github.com/jgmize/django-google-drive/tree/master/gdrive/gdoauth2https://github.com/praekelt/django-google-credentials/tree/master/google_credentials 等)将 Credentials 放在用户个人资料的 CredentialsField 字段中,并将其保存到数据库中。

这两种方法的优点/缺点是什么?有偏好吗?

谢谢。

【问题讨论】:

  • 如果有人在 2020 年关注这个问题,我会选择官方的 Google API 方法。老实说——它们看起来并没有太大的不同(尽管我可能并不完全理解这些差异)。但总的来说,如果您使用的是 Google API,他们可能已经对如何最好地配置它进行了相当多的思考。
  • @bones225 你能分享一下Google API方法的链接吗?
  • @shaikmoeed 看起来 oauth2client 已被弃用,github.com/googleapis/oauth2client

标签: django google-api google-oauth google-api-client oauth2client


【解决方案1】:

要使用 google 功能实现登录,您可以使用 django-allauth https://django-allauth.readthedocs.io/en/latest/

它提供易于集成的 Django 应用程序集,解决身份验证、注册、帐户管理以及 3rd 方(社交)帐户身份验证。

https://django-allauth.readthedocs.io/en/latest/providers.html#google

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-08-08
    • 2019-03-21
    • 2021-01-14
    • 2017-10-30
    • 2011-09-12
    • 1970-01-01
    • 2013-06-10
    • 1970-01-01
    相关资源
    最近更新 更多