Django的Dresses话语SSO客户端

kleides-dssoclient的Python项目详细描述


话语单点登录(dsso)提供程序客户端 django项目到discussion单一登录提供程序服务器

见:https://meta.discourse.org/t/official-single-sign-on-for-discourse-sso/

示例用法:

  • kleides_dssoclient添加到INSTALLED_APPS

  • 创建自定义DssoLoginBackend,例如:

    from kleides_dssoclient.backends import DssoLoginBackend
    
    class MyProjectDssoLoginBackend(DssoLoginBackend):
        """
        DssoLoginBackend that rejects anyone without is_superuser, and that
        sets all mapped variables on the newly created User object.
        """
        def authenticate(self, dsso_mapping):
            """
            Check that user is a superuser and pass along to DssoLoginBackend.
            """
            if dsso_mapping.get('is_superuser') not in ('True', 'true', '1'):
                return None
    
            return super(MyProjectDssoLoginBackend, self).authenticate(
                dsso_mapping)
    
        def configure_user(self, user, dsso_mapping):
            """
            We expect username, email, is_superuser in the dsso_mapping.
            """
            user = (
                super(MyProjectDssoLoginBackend, self)
                .configure_user(user, dsso_mapping))
    
            user.email = dsso_mapping.get('email', '')
            is_superuser = (
                dsso_mapping.get('is_superuser') in ('True', 'true', '1'))
            user.is_staff = is_superuser
            user.is_superuser = is_superuser
    
            user.save()
            return user
    
  • 将此项添加到djangosettings

    AUTHENTICATION_BACKENDS = (  # the only backend needed
        'myproject.backends.MyProjectDssoLoginBackend',
    )
    MIDDLEWARE_CLASSES += (
        'kleides_dssoclient.middleware.DssoLoginMiddleware',
    )
    KLEIDES_DSSO_ENDPOINT = 'https://DSSOSERVER/sso/'
    KLEIDES_DSSO_SHARED_KEY = 'oh-sso-very-very-secret'
    

更改

V0.7-2019-07-16

  • 允许通过将kleides_dsso_endpoint设置为none来绕过中间件。

V0.6-2019-03-06

  • 为django 2.1添加requestarg到DssoLoginBackend

V0.5-2019-03-06

  • 添加日志以帮助调查问题。

v0.3-2018-12-18

  • 添加对django 1.10风格中间件的支持。
  • 检查Django版本是否有经过身份验证的用法。

v0.2-2018-11-19

  • 在authenticate参数列表中将sso_mapping替换为dsso_mapping

v0.1-2018-11-16

  • 初次发布。

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

推荐PyPI第三方库


热门话题
java log4j找不到log4jtest。房产?   我在java线程“awteventque1”中获得异常。lang.NullPointerException   java为什么在使用完整路径从文件系统读取文件时出错?   java如何迭代所有注册表项?   java中的安卓 Opencv SVM未正确训练   多线程Java ThreadPoolExecutor关闭特定线程?   如何使用Java NIO CreateDirectory方法设置目录所有者组?   java NatTable混合了固定宽度的列和可调整大小的填充剩余空间   java如何删除特定网络,即使该网络是由安卓上的其他设备创建的?   java Guava toJavaUtil()不存在   java对许多常量使用枚举是有效的memorywise?   java是否可以使用坐标定位JButton?   从WSDL生成java代码导致异常   java如何在安卓中导出javadoc   爬行JAX中的java NoClassDefFoundError错误   java为片段中的文本视图设置区域设置   发送最后一条消息后发生Java RMI RemoteException