zoukankan      html  css  js  c++  java
  • sso单点登陆

    为了简化开发流程,使用了django 的用户管理机制。项目中需要实现sso单点登录,保障系统能够整合到原有旧平台中。

    (1)在app中添加authbackend.py 。 yourapp/auth_backend.py

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    from django.contrib.auth.backends import ModelBackend
    from django.contrib.auth.models import User
     
     
    class PasswordlessAuthBackend(ModelBackend):
        """Log in to Django without providing a password.
     
        """
        def authenticate(self, username=None):
            try:
                return User.objects.get(username=username)
            except User.DoesNotExist:
                return None
     
        def get_user(self, user_id):
            try:
                return User.objects.get(pk=user_id)
            except User.DoesNotExist:
                return None

     (2)设置setting.py

    1
    2
    3
    4
    AUTHENTICATION_BACKENDS = (
        # ... your other backends
        'yourapp.authbackend.PasswordlessAuthBackend',
    )

     (3)在自己的view中可以直接使用

    1
    2
    user = authenticate(username=user.username)
    login(request, user)
     
  • 相关阅读:
    MySql常用数据操作
    使用requests+BeaBeautiful Soup爬取妹子图图片
    抓取猫眼电影排行
    Exec执行拼接字符串时遇到的问题及Sql执行函数时需要注意的事项
    c#小知识点
    MVVM 与 sql
    Dictionary
    sql表信息查询
    XAML特殊字符
    编程细节
  • 原文地址:https://www.cnblogs.com/xiao-zang/p/15212315.html
Copyright © 2011-2022 走看看