django-auth_从django-social-auth迁移到python-social-auth

news/2024/7/23 10:49:41 标签: python, java, django, .net, 数据库

django-auth

I recently ported an app with Google OAuth2 integration from django-social-auth to python-social-auth. Here are some things I noticed that were not mentioned in the porting docs.

最近,我将集成了Google OAuth2的应用程序从django-social-auth移植到python-social-auth 。 这是我注意到的一些移植文档中未提及的内容。

(Note: In the following text I will refer to django-social-auth and

(注意:在下文中,我将参考django-social-auth和

迁移数据库 (Migrating Database)

Last week I migrated the application to Django 1.7. Now that I also switched from DSA to PSA, I wanted to run the migrations but discovered a problem…

上周,我将应用程序迁移到了Django 1.7。 现在,我也从DSA切换到PSA,我想运行迁移,但是发现了一个问题……


$ ./manage.py migrate default
Operations to perform:
  Target specific migration: 0001_initial, from default
Running migrations:
  Applying default.0001_initial...Traceback (most recent call last):

(...)

django.db.utils.ProgrammingError: relation "social_auth_association" already exists

(Note that default is the short name of the PSA Django app, because the full path is social.apps.django_app.default.)

(请注意, 默认值是PSA Django应用程序的简称,因为完整路径是social.apps.django_app.default 。)

The problem is that PSA tried to create the initial models, but failed because they already existed back from DSA.

问题是PSA尝试创建初始模型,但失败了,因为它们已经从DSA重新存在了。

The porting docs mention that “the models table names were defined to be compatible with those used on django-social-auth, so data is not needed to be migrated”. Therefore we can safely skip the initial migration by faking it:

移植文档提到“模型表名称被定义为与django-social-auth上使用的名称兼容,因此不需要迁移数据”。 因此,我们可以通过伪造来安全地跳过初始迁移:


$ ./manage.py migrate default 0001 --fake
Operations to perform:
  Target specific migration: 0001_initial, from default
Running migrations:
  Applying default.0001_initial... FAKED

Now we’re at a valid state and can run all other migrations:

现在我们处于有效状态,可以运行所有其他迁移:


$ ./manage.py migrate

刷新访问令牌 (Refreshing an Access Token)

The old way to refresh an access token was the following line of code:

刷新访问令牌的旧方法是以下代码行:

 useruser .. social_authsocial_auth .. getget ()() .. refresh_tokenrefresh_token ()
()

This fails with an exception though:

但是,此操作失败,但有一个例外:


TypeError: refresh_token() takes at least 2 arguments (1 given)

The reason is that the refresh_token method now expects a strategy instance as argument. The Django strategy can be loaded using the following code snippet:

原因是refresh_token方法现在希望将策略实例作为参数。 可以使用以下代码段加载Django策略:

UserSocialAuth.tokens (UserSocialAuth.tokens)

In DSA, the tokens property of a UserSocialAuth instance used to return a dictionary of tokens, containing keys like access_token. Now it returns the access token directly. I created an issue in the PSA issue tracker, because I find the naming a bit confusing.

在DSA中, UserSocialAuth实例的tokens属性用于返回令牌字典,其中包含诸如access_token之类的键。 现在,它直接返回访问令牌。 我在PSA问题跟踪器中创建了一个问题 ,因为我发现命名有些混乱。

简化管道扩展 (Simplified Pipeline Extension)

If you want to extend the default pipeline, the old way was to copy-paste the code from the DSA sourcecode and add your custom pipeline entries to it. In PSA, you now have a DEFAULT_AUTH_PIPELINE tuple that can be used in your definition.

如果要扩展默认管道,则旧方法是从DSA源代码中复制粘贴代码,然后向其中添加自定义管道条目。 在PSA中,您现在可以使用DEFAULT_AUTH_PIPELINE元组。

 from from social.pipeline social.pipeline import import DEFAULT_AUTH_PIPELINE

DEFAULT_AUTH_PIPELINE

SOCIAL_AUTH_PIPELINE SOCIAL_AUTH_PIPELINE = = DEFAULT_AUTH_PIPELINE DEFAULT_AUTH_PIPELINE + + (
    (
    'config.social_auth.fetch_account_access''config.social_auth.fetch_account_access' ,
,
)
)

翻译自: https://www.pybloggers.com/2014/10/migrating-from-django-social-auth-to-python-social-auth/

django-auth


http://www.niftyadmin.cn/n/983567.html

相关文章

利用Gulp搭建本地服务器并实现Ajax模拟

2019独角兽企业重金招聘Python工程师标准>>> 利用gulp搭建本地服务器,实现自动打开页面,自动刷新,模拟ajax操作 用到的模块如下: gulpgulp-webservergulp-livereload第一步,创建package.json npm init第二步…

Git学习(二)(2015年11月18日)(2016年1月29日)

2015年11月18日Git学习:15、Shell 删除文件夹及其所有文件 rd/s/q 文件目录---------------当前为先创建本地Git库后与网上Git服务器关联---------------------- 16、远程仓库第一步:创建ssh keyssh-keygen -t rsa -C "xyzhuzhou163.com"第二步&#xff…

cpu和内存的关系

CPU是负责运算和处理的,内存是交换数据的。当程序或者操作者对CPU发出指令,这些指令和数据暂存在内存里,在CPU空闲时传送给CPU,CPU处理后把结果输出到输出设备上,输出设备就是显示器,打印机等。在没有显示完…

django 上传 缩略图_使用django-thumbnail-works生成图像缩略图。

django 上传 缩略图Uploading images to our Django application can be as easy as adding an ImageField to our model. However, ImageField falls short in one key aspect, thumbnails. Usually when uploading images, we want to create smaller versions for them, for…

13.9k Star, 3.6k Fork —— 技术人如何从0到1打造成功的开源软件?

作者丨王一鹏开源,曾被认为是 IT 科技的“文艺复兴”。但在很长一段时间内,国内开源文化的发展并不乐观 —— 许多开发者将开源理解为“代码 Copy”,对开源精神产生了极大的误解。这种误解,对开源软件的发展,多少产生了…

android的padding和margin的区别

android:padding和android:layout_margin的区别:padding是站在父view的角度描述问题,它规定它里面的内容必须与这个父view边界的距离。 margin则是站在自己的角度描述问题,规定自己和其他(上下左右)的 view之间的距离,…

kali修改时间

今天重装了kali,选择的时区是美国时间,linux默认的时间设置使用格林威治时间,即从本初子午线为0时区,其他地区以0时区为起始位置进行换算。 中国所在时区为东八区,应该使用GMT8,本来之前安装双系统&#x…

基于django的web_使用Django和GeoDjango制作基于位置的Web应用

基于django的webThroughout this tutorial, you’ll learn how to use Django and GeoDjango to build a location-based web application from scratch. You’ll be building a simple nearby shops application that lists the shops closest to a user’s location. 在整个…