美文网首页
django-simple-sso实现单点登陆

django-simple-sso实现单点登陆

作者: tonyemail_st | 来源:发表于2019-08-27 21:02 被阅读0次

django-simple-sso原始workflow

  1. User wants to log into a Client by clicking a “Login” button. The initially requested URL can be passed using the next GET parameter.
  2. The Client’s Python code does a HTTP request to the Server to request a authentication token, this is called the Request Token Request.
  3. The Server returns a Request Token.
  4. The Client redirects the User to a view on the Server using the Request Token, this is the Authorization Request.
  5. If the user is not logged in the the Server, they are prompted to log in.
  6. The user is redirected to the Client including the Request Token and a Auth Token, this is the Authentication Request.
  7. The Client’s Python code does a HTTP request to the Server to verify the Auth Token, this is called the Auth Token Verification Request.
  8. If the Auth Token is valid, the Server returns a serialized Django User object.
  9. The Client logs the user in using the Django User recieved from the Server.

前后端分离项目使用django-simple-sso的验证过程

image.png
  1. 用户请求前端页面,前端页面请求get_user_info接口,session有效可以返回用户信息。
  2. 当无法获取用户信息时,说明client端登陆失效。调用client端登陆接口。此接口会向server端获取request-token。server端会保存此token到token表中。
  3. user被重定向到server端的authorize接口,参数request-token。验证server端session是否有效,
"GET /server/authorize/?token=adpvzavQValZBGCzpGJE2QpnRQxNJVlWpQJ4h0uP8d2CuK0P7tBGuBXbUuyBqQyT HTTP/1.1" 302 0
  1. 无效则重定向到登陆页面,登陆后再次请求authorize接口。
  2. 有效则重定向到client端authenticate接口。此接口会向server端请求用户信息,并且请用户信息保存在client端的auth_user表中

部分代码

因为要实现不同域名之间的跳转,所以覆盖了原代码中的get_next方法,不进行任何安全限制。

class ClientLoginView(client.LoginView):
    def get_next(self):
        return self.request.GET.get('next', None)  # 允许跳转到外部域

class ClientAuthenticateView(client.AuthenticateView):

    def get(self, request):
        raw_access_token = request.GET['access_token']
        access_token = URLSafeTimedSerializer(self.client.private_key).loads(raw_access_token)
        user = self.client.get_user(access_token)
        user.backend = self.client.backend
        login(request, user)
        next = self.get_next()
        return HttpResponseRedirect(next)

    def get_next(self):
        return self.request.GET.get('next', None)  # 允许跳转到外部域

相关文章

  • django-simple-sso实现单点登陆

    django-simple-sso原始workflow User wants to log into a Clie...

  • 登陆相关

    CookieSession原理单点登录的3中实现方式登陆那些事儿

  • 单点登陆SSO(Single Sign On)

    Q:什么是单点登陆 在多系统应用群众登陆一个系统,便可在其他所有系统中得到授权而无需再次登陆,包括单点登陆和单点注...

  • php实现sso(单点登陆)

    实例:用户在A网站登陆,B,C,D,E网站也同时登陆。 1:用户A在A网站登陆,然后进入到S(用户身份认证中心)进...

  • Session和EL表达式实现登陆验证

    现在多系统的登陆都采用单点登陆了,emmmm......后期再更单点登陆的,这次由于只是个小demo,所以我们采用...

  • cas 单点登录

    CAS 单点登录简介cas单点登陆。就这一篇就够了!!!!!

  • SSO单点登录

    单点登陆 单系统登陆如何实现 示例:客户端向服务端发送请求,首次请求受保护资源时,服务端生成cookie并返回给客...

  • 网络安全之反序列化漏洞复现

    0x01 Apereo cas简介 Apereo CAS 单点登陆系统是Java服务器环境下使用较为广泛的单点登陆...

  • 单点登陆

    单系统登陆 普通的单个系统登陆流程是什么样子的呢?用户访问系统,如果访问的是受限制的资源,比如http://loc...

  • 单点登陆

    一、前言 什么是SSO? SSO英文全称Single Sign On,单点登录。SSO是在多个应用系统中,用户只需...

网友评论

      本文标题:django-simple-sso实现单点登陆

      本文链接:https://www.haomeiwen.com/subject/wwosectx.html