将BankID(瑞典认证服务)集成到Django中的Python中进行登录

Integrating BankID (Swedish authentication service) into Python in Django to login

我是 Django 的新手,但这里是。

我想在我的 Web 应用程序中使用 Django 集成第三方验证服务,特别是 BankID。
BankID 是一种公民身份识别解决方案,允许公司、银行和政府机构在瑞典通过 Internet 对个人进行身份验证并与其签订协议。

BankID 应用作登录验证(BankID 和 Mobile BankID),请参阅示例网站:https://e-tjanster.1177.se/mvk/login/login.xhtml

我已阅读他们的开发者指南:https://www.bankid.com/assets/bankid/rp/bankid-relying-party-guidelines-v3.4.pdf

但我想通过 Django 来实现。 Django 有一个休息框架,我一直在尝试使用,但没有成功:https://www.django-rest-framework.org/

不通过Django在Python中应用bankID的示例代码(我想在Django中应用下面这个): https://github.com/fiso/smooth-bankid/blob/master/README.md https://github.com/fiso/smooth-bankid/tree/master/examples/python

我的网络应用:https://defreitasbolaget.herokuapp.com

My Requirement.txt file is:

boto3==1.9.96
botocore==1.12.96
certifi==2018.10.15
cffi==1.14.1
chardet==3.0.4
cryptography==3.0
dj-database-url==0.5.0
Django==2.1
django-crispy-forms==1.7.2
django-heroku==0.3.1
django-storages==1.7.1
docutils==0.14
gunicorn==19.9.0
idna==2.7
jmespath==0.9.3
Pillow==5.2.0
psycopg2==2.7.7
pycparser==2.20
pyOpenSSL==19.1.0
python-dateutil==2.8.0
pytz==2018.5
requests==2.19.1
s3transfer==0.2.0
six==1.12.0
urllib3==1.23
whitenoise==4.1.2

结论:我想将 BankID(瑞典语版本)集成到我的 Django Python 应用程序中。做这个的最好方式是什么?感谢任何帮助。

你需要:

  • 编写您的自定义用户模型以集成BankID并通过settings.py
  • 中的AUTH_USER_MODEL覆盖默认模型

参考https://docs.djangoproject.com/en/2.2/topics/auth/customizing/#substituting-a-custom-user-model

并仔细查看 https://github.com/django/django/blob/master/django/contrib/auth/models.py

中的 AbstractUser
  • 编写您的自定义身份验证后端并通过settings.py
  • 中的AUTHENTICATION_BACKENDS覆盖默认后端

参考https://docs.djangoproject.com/en/3.1/topics/auth/customizing/

并仔细查看 https://github.com/django/django/blob/master/django/contrib/auth/backends.py

中的 ModelBackend

但我认为最好的方法是将 BankID 身份验证作为第三个 Django 扩展/包实施,并继续独立更新它。

更新

参考这个项目https://pypi.org/project/pybankid/

PyBankID is a client for providing BankID services as a Relying Party, i.e. providing authentication and signing functionality to end users. This package provides a simplifying interface for initiating authentication and signing orders and then collecting the results from the BankID servers.

和这个项目https://pypi.org/project/Flask-PyBankID/

A Flask extension for using PyBankID on your site.

获得想法并将其移植到 django。