Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Developing an SSO service using Django - PyCon ...

Vibhu
November 11, 2020

Developing an SSO service using Django - PyCon Sweden 2020

Live stream: https://youtu.be/4BN2Np7fUqY

Abstract: Single-Sign-On (SSO) allows users to authenticate with a single ID and password to any of several related, yet independent, software systems. In this talk, we'll discuss how an SSO works and how it can be designed. We'll also see the code to implement it in Python using Django (REST Framework).

About the speaker: Vibhu Agarwal is an avid Pythonista, open-source enthusiast and a Back-End Developer at Viga Entertainment Technology, developing applications serving different UIs (Web, Desktop, AR/VR) and designing CI/CD pipelines for their delivery.

Vibhu

November 11, 2020
Tweet

More Decks by Vibhu

Other Decks in Programming

Transcript

  1. Developing a Single-Sign-On Service using Django @vibhu4agarwal PyCon Sweden 2020

    github.com/Vibhu-Agarwal/Developing-an-SSO-Service-using-Django
  2. - He/him - Student - Pythonista - Django User -

    Back-End Developer at VigaStudios Vibhu Agarwal (@vibhu4agarwal) PyCon Sweden 2020
  3. Why? For User • Only one password to remember •

    Better UX For Service Providers • Management: ◦ Database ◦ Session • User-account Support • Security Layers @vibhu4agarwal PyCon Sweden 2020
  4. JWT { "alg": "HS256", "typ": "JWT", } { "sub": "1234567890",

    "name": "John Doe", "iat": 1516239022 } HEADER PAYLOAD xxxxx . yyyyy . zzzzz HMAC-SHA256( base64UrlEncode(header). base64UrlEncode(payload), secret_key) SIGNATURE @vibhu4agarwal PyCon Sweden 2020
  5. Access and Refresh Tokens a short live demo? @vibhu4agarwal PyCon

    Sweden 2020 github.com/Vibhu-Agarwal/Developing-an-SSO-Service-using-Django
  6. What’s the point? No worries about third-parties Release some control

    to Clients Customization of Flow @vibhu4agarwal PyCon Sweden 2020
  7. Solutions with secret_key method (HMAC-SHA256) 1. Distribute the secret_key itself

    2. Dedicated service for token generation and verification @vibhu4agarwal PyCon Sweden 2020
  8. Solutions with secret_key method (HMAC-SHA256) 1. Distribute the secret_key itself

    2. Dedicated service for token generation and verification @vibhu4agarwal PyCon Sweden 2020
  9. Asymmetric Cryptography (Public + Private Keys) (RSA-SHA256) Private Key: Creates

    Signatures Public Key: Verifies Signatures @vibhu4agarwal PyCon Sweden 2020
  10. Asymmetric Cryptography (Public + Private Keys) (RSA-SHA256) Private Key: Creates

    Signatures Public Key: Verifies Signatures Public Key: Encrypts messages Private Key: Decrypts messages @vibhu4agarwal PyCon Sweden 2020
  11. Django Django-REST-Framework (DRF) Libraries first ... The Framework @vibhu4agarwal PyCon

    Sweden 2020 github.com/Vibhu-Agarwal/Developing-an-SSO-Service-using-Django
  12. djangorestframework-simplejwt requests Libraries first ... JSON-Web-Tokens and Making Requests @vibhu4agarwal

    PyCon Sweden 2020 github.com/Vibhu-Agarwal/Developing-an-SSO-Service-using-Django
  13. Client JWTAuthentication backend??? @vibhu4agarwal PyCon Sweden 2020 authenticate() Looks up

    the User in the database corresponding to the user-ID provided in the JWT
  14. Client JWTTokenUserAuthentication backend @vibhu4agarwal PyCon Sweden 2020 authenticate() No DB-lookup

    to obtain a user instance TokenUser A stateless user object backed only by a validated token
  15. Commonly used Protocols … with different implementations SAML and WS-Fed

    - XML OpenID Connect - JWT LDAP/AD - LDIF @vibhu4agarwal PyCon Sweden 2020 auth0.com/docs/sso#protocols
  16. Resources • OpenID Connect • Map of OAuth 2.0 Specs

    • cryptography - Asymmetric Algorithms • DRF - Writing Custom Permissions • Writing Generic API Views using DRF @vibhu4agarwal PyCon Sweden 2020 github.com/Vibhu-Agarwal/Developing-an-SSO-Service-using-Django