django sso客户端应用程序,与dj sso服务器一起工作

dj-sso-client2的Python项目详细描述


dj-sso-client是django应用程序作为dj-sso-serverhttps://github.com/feifangit/dj-sso-server)的sso客户端工作

安装

pip install dj-sso-client

添加到项目中

  • 在项目的settings.py中修改以下设置

    • ^{tt5}$, add ^{tt6}$ as the backends
    • ^{tt7}$, set ^{tt8}$ as user model
AUTHENTICATION_BACKENDS=('djssoclient.authbackend.SSOAuthBackend',)AUTH_USER_MODEL='djssoclient.SSOUser'
  • 根据需要添加以下dj-sso-client设置

    • ^{tt10}$: set API key, SEC key and remote SSO provider URL. This setting is used by underneath ^{tt11}$ module to proejct API accessing.

      SSO_API_AUTH_SETTING={"apikey":"f4a05287","seckey":"6a4eeaea54d54f51af703e79c6096d51","url":"https://dj-sso-sample.herokuapp.com",}
    • SSO_REMOTE_URL_PREFIX(可选):远程SSO提供程序中的SSO路径。默认值/sso/

    • SSO_USER_STORAGE``(optional):  SSOUser storage solution, there are 2 storage backends in ``dj-sso-client已经。默认值:ssouserdbstorage

      • ^{tt15}$: store user data in database
      • ^{tt16}$: store user data in cache. You will get better performance.
    • SSO_SETTING_CACHE(可选):如果选择SSOUserCacheStorage作为用户存储后端,并且在settings.py中有多个缓存,则可以在此处拾取缓存名称。默认值:default

注意:SSOUserCacheStorage

默认的django.core.cache.backends.locmem.LocMemCache存储每个进程的数据。在多进程生产环境(多核服务器上的gunicorn)中,使用SSOUserCacheStorage作为用户存储引擎时可能会出现问题。

请使用专用缓存系统(memcached或redis)作为缓存后端,以避免此问题。

ssouser

SSOUser是存储用户数据的用户模型。如果选择SSOUserDBStorage作为用户存储引擎,则可以将其用作数据库模型类。

classSSOUser(AbstractBaseUser):username=models.CharField(unique=True,max_length=50)extras=models.TextField(default="{}")...

^ {STR 1 }额外的用户属性>:^ {tT24} $类中不存在属性。(除了usernamepasswordlast_login等属性)

所有额外的用户属性都可以由getattr方法或.运算符访问。它们以json格式存储在类成员extras中。

把手弄脏

我们已经有一个sso提供程序(dj-sso-server)应用程序在heroku:http://dj-sso-sample.herokuapp.com/上运行。在本地文件夹example/ssoclient/中运行示例应用程序。

示例应用程序中使用的api键与localhost:8000绑定,因此请确保通过localhost:8000而不是127.0.0.1:8000访问本地应用程序。

fresh登录

  1. 确保您没有登录http://dj-sso-sample.herokuapp.com/,您应该会看到please log in with ...
  2. 单击本地应用程序上的sso login,将重定向到http://dj-sso-sample.herokuapp.com/sso/…。
  3. 重定向到本地应用程序后,您将看到用户信息。
  4. http://dj-sso-sample.herokuapp.com/上,您的状态仍然未登录

^ {STR 1 }登录现有登录帐户< /强>

  1. 使用用户名user1和密码123登录http://dj-sso-sample.herokuapp.com/
  2. 单击本地应用程序上的sso login,您将被重定向到http://dj-sso-sample.herokuapp.com/sso/….,但您将看到另一个新登录的登录页面。
  3. 选择continue with current user? user1
  4. 您将以user1身份登录本地应用程序

切换帐户

  1. 如果您选择switch account,并使用user2/456从上一个示例的步骤3登录
  2. 您将以user2身份登录本地应用程序
  3. 您在http://dj-sso-sample.herokuapp.com/上的登录状态将更改(仍以user1登录)

待办事项

  • 示例:作为额外的auth方法工作

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java在OSGi felix scr注释中将运行时参数传递给服务   java如何按字母顺序将对象插入ArrayList?   在Netbeans中调试Java   java从json文件中获取不同的照片   通过迭代和打印将java插入2个哈希表的运行时间   java如何替换JUnit 5中的WireMock@Rule注释?   shell在javajsch程序中使用'been'命令访问受限目录   java RMI是什么类型的?   javajooq别名构造   java如何通过在testNG中创建对象来调用测试方法   java下载从安卓 URL加载到imageview中的图像   从java运行bat文件   带有客户端证书的java嵌入式Jetty   java Ajax将JSON数组发送到servlet   创建数据并将数据添加到SQLite数据库时发生java错误   添加CV的javascript HRMS项目过程   java AspectJ加载时编织不起作用   java动态更改(使用JMX)正在监视的文件夹中的新文件   java岛数迭代矩阵并将节点标记为已访问