SlideShare a Scribd company logo
1 of 49
Registration &
Authentication
A story about Django and OAUTH
Daniel Greenfeld
                                                                                 @pydanny




                               Who am I?

                                                 Daniel Greenfeld (@pydanny)
                                                 Pythonista at Cartwheel
                                                 Djangonaut at Revsys
                                                 http://opencomparison.org
                                                 Fiancé of Audrey Roy


http://www.flickr.com/photos/pydanny/4442245488
Why am I talking?
We have needs
Daniel Greenfeld
                     @pydanny




What we need
Daniel Greenfeld
                                    @pydanny




       What we need

• Registration of new users
Daniel Greenfeld
                                           @pydanny




       What we need

• Registration of new users
• Authentication of existing users
Daniel Greenfeld
                                                 @pydanny




       What we need

• Registration of new users
• Authentication of existing users
• Unless we are an ad-click content farm
Daniel Greenfeld
                  @pydanny




Use OAUTH
Daniel Greenfeld
                                          @pydanny




        Use OAUTH

• People use Twitter/Facebook/etc
Daniel Greenfeld
                                          @pydanny




        Use OAUTH

• People use Twitter/Facebook/etc
• Fewer passwords to memorize
Daniel Greenfeld
                                           @pydanny




        Use OAUTH

• People use Twitter/Facebook/etc
• Fewer passwords to memorize
• Our site needn’t store passwords
Daniel Greenfeld
                                                   @pydanny




        Use OAUTH

• People use Twitter/Facebook/etc
• Fewer passwords to memorize
• Our site needn’t store passwords
• Twitter/Facebook/etc gets to worry about
  security
But OAUTH
  is a pain
Everyone implements
    it differently
Daniel Greenfeld
                         @pydanny




Different flavors
Daniel Greenfeld
                              @pydanny




     Different flavors

• Twitter
Daniel Greenfeld
                              @pydanny




     Different flavors

• Twitter
• Facebook
Daniel Greenfeld
                              @pydanny




     Different flavors

• Twitter
• Facebook
• Google
Daniel Greenfeld
                              @pydanny




     Different flavors

• Twitter
• Facebook
• Google
• Linkedin
Daniel Greenfeld
                                     @pydanny




     Different flavors

• Twitter
• Facebook   • Github (YAY!)
• Google
• Linkedin
Daniel Greenfeld
                                     @pydanny




     Different flavors

• Twitter
• Facebook   • Github (YAY!)
• Google     • Facebook ARGH
• Linkedin
Daniel Greenfeld
                                                   @pydanny




      Different flavors

• Twitter
• Facebook          • Github (YAY!)
• Google            • Facebook ARGH
• Linkedin
The OAUTH specification is not honored well
Daniel Greenfeld
                                                      @pydanny




          Different flavors

    • Twitter
    • Facebook          • Github (YAY!)
    • Google            • Facebook ARGH
    • Linkedin
   The OAUTH specification is not honored well
Implementation changes are sometimes not announced
You want a tool used
  by many people
Many people means
   lots of eyes
Let’s find a tool!
Daniel Greenfeld
                                                      @pydanny




   Django Auth Options




http://djangopackages.com/grids/g/authentication/
Daniel Greenfeld
                                                      @pydanny




   Django Auth Options

                Dozens more if
                  you scroll




http://djangopackages.com/grids/g/authentication/
Daniel Greenfeld
                                                  @pydanny




       Many problems

• django-tastypie and Piston are for APIs
• Most of these lack tests
• Most of these lack documentation
• Bad code smell
They all suck for
   OAUTH?
One Good Tool!
Daniel Greenfeld
                                                     @pydanny




    django-social-auth


• https://github.com/omab/django-social-auth
• http://django-social-auth.rtfd.org
Daniel Greenfeld
                           @pydanny




django-social-auth
Daniel Greenfeld
                               @pydanny




    django-social-auth

• Tests!
Daniel Greenfeld
                               @pydanny




    django-social-auth

• Tests!
• Docs!
Daniel Greenfeld
                               @pydanny




    django-social-auth

• Tests!
• Docs!
• Good code smell!
Daniel Greenfeld
                                                         @pydanny




                   Statistics




http://djangopackages.com/packages/p/django-social-auth/
Daniel Greenfeld
                                                         @pydanny




                   Statistics


                 Many
               downloads




http://djangopackages.com/packages/p/django-social-auth/
Daniel Greenfeld
                                                         @pydanny




                   Statistics
                                Ongoing development



                 Many
               downloads




http://djangopackages.com/packages/p/django-social-auth/
Daniel Greenfeld
                                                         @pydanny




                   Statistics
                                Ongoing development



                 Many
               downloads



   Many eyes on the problem
http://djangopackages.com/packages/p/django-social-auth/
Using
django-social-auth
Daniel Greenfeld
                                        @pydanny




    Get the dependency


pip install django-social-auth==0.5.13
Daniel Greenfeld
                                                             @pydanny




      Part I: settings.py
INSTALLED_APPS = (
    ...
    'social_auth',
    ...
)

AUTHENTICATION_BACKENDS = (
    'social_auth.backends.contrib.github.GithubBackend',
# keep this so you have that admin level backend access!
    'django.contrib.auth.backends.ModelBackend',
)
Daniel Greenfeld
                                                                 @pydanny




         Part II: settings.py
from django.template.defaultfilters import slugify
SOCIAL_AUTH_ENABLED_BACKENDS = ('github',)
SOCIAL_AUTH_COMPLETE_URL_NAME = 'socialauth_complete'
SOCIAL_AUTH_ASSOCIATE_URL_NAME = 'associate_complete'
SOCIAL_AUTH_DEFAULT_USERNAME = lambda u: slugify(u)
SOCIAL_AUTH_EXTRA_DATA = False
SOCIAL_AUTH_CHANGE_SIGNAL_ONLY = True

SOCIAL_AUTH_ASSOCIATE_BY_MAIL = True # associate user via email



 (Usually you can just go with these as your settings)
Daniel Greenfeld
                                                   @pydanny




Part III: root urls.py

 urlpatterns = patterns("",
     url('', include('social_auth.urls')),
     ...
     )
Daniel Greenfeld
                                                                        @pydanny




          Part IV: profile/views.py
from social_auth.signals import pre_update
from social_auth.backends.contrib.github import GithubBackend

from profiles.models. import Profile

def github_user_update(sender, user, response, details, **kwargs):
    profile_instance, created = Profile.objects.get_or_create(user=user)
    profile_instance.save()
    return True

pre_update.connect(github_user_update, sender=GithubBackend)



(Not specifying this view in urls - django-social-auth does it for me)
Daniel Greenfeld
                                         @pydanny




 Try it yourself!




http://djangopackages.com/login/
Thanks!

More Related Content

Viewers also liked

Best Practices for Front-End Django Developers
Best Practices for Front-End Django DevelopersBest Practices for Front-End Django Developers
Best Practices for Front-End Django Developers
Christine Cheung
 
From NASA to Startups to Big Commerce
From NASA to Startups to Big CommerceFrom NASA to Startups to Big Commerce
From NASA to Startups to Big Commerce
Daniel Greenfeld
 

Viewers also liked (11)

The One Way
The One WayThe One Way
The One Way
 
PyCon Philippines 2012 Keynote
PyCon Philippines 2012 KeynotePyCon Philippines 2012 Keynote
PyCon Philippines 2012 Keynote
 
Intro
IntroIntro
Intro
 
Intro to Data Visualizations
Intro to Data VisualizationsIntro to Data Visualizations
Intro to Data Visualizations
 
Best Practices for Front-End Django Developers
Best Practices for Front-End Django DevelopersBest Practices for Front-End Django Developers
Best Practices for Front-End Django Developers
 
Round pegs and square holes
Round pegs and square holesRound pegs and square holes
Round pegs and square holes
 
Python Programming Essentials - M34 - List Comprehensions
Python Programming Essentials - M34 - List ComprehensionsPython Programming Essentials - M34 - List Comprehensions
Python Programming Essentials - M34 - List Comprehensions
 
Python Programming Essentials - M44 - Overview of Web Development
Python Programming Essentials - M44 - Overview of Web DevelopmentPython Programming Essentials - M44 - Overview of Web Development
Python Programming Essentials - M44 - Overview of Web Development
 
Intro to Python
Intro to PythonIntro to Python
Intro to Python
 
10 more-things-you-can-do-with-python
10 more-things-you-can-do-with-python10 more-things-you-can-do-with-python
10 more-things-you-can-do-with-python
 
From NASA to Startups to Big Commerce
From NASA to Startups to Big CommerceFrom NASA to Startups to Big Commerce
From NASA to Startups to Big Commerce
 

Similar to Lighting talk on django-social-auth (6)

Confessions of Joe Developer
Confessions of Joe DeveloperConfessions of Joe Developer
Confessions of Joe Developer
 
A birds eye view of social media for education
A birds eye view of social media for educationA birds eye view of social media for education
A birds eye view of social media for education
 
Google's internal systems
Google's internal systemsGoogle's internal systems
Google's internal systems
 
Google's internal systems
Google's internal systemsGoogle's internal systems
Google's internal systems
 
How to help Greenpeace online
How to help Greenpeace onlineHow to help Greenpeace online
How to help Greenpeace online
 
Ranking in Google Discover
Ranking in Google DiscoverRanking in Google Discover
Ranking in Google Discover
 

More from Daniel Greenfeld

More from Daniel Greenfeld (10)

Advanced Django Forms Usage
Advanced Django Forms UsageAdvanced Django Forms Usage
Advanced Django Forms Usage
 
Django Worst Practices
Django Worst PracticesDjango Worst Practices
Django Worst Practices
 
How to sell django panel
How to sell django panelHow to sell django panel
How to sell django panel
 
Pinax Long Tutorial Slides
Pinax Long Tutorial SlidesPinax Long Tutorial Slides
Pinax Long Tutorial Slides
 
Testing In Django
Testing In DjangoTesting In Django
Testing In Django
 
Django Uni-Form
Django Uni-FormDjango Uni-Form
Django Uni-Form
 
Nova Django
Nova DjangoNova Django
Nova Django
 
Pinax Introduction
Pinax IntroductionPinax Introduction
Pinax Introduction
 
Why Django
Why DjangoWhy Django
Why Django
 
Pinax Tutorial 09/09/09
Pinax Tutorial 09/09/09Pinax Tutorial 09/09/09
Pinax Tutorial 09/09/09
 

Recently uploaded

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Recently uploaded (20)

Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 

Lighting talk on django-social-auth

  • 1. Registration & Authentication A story about Django and OAUTH
  • 2. Daniel Greenfeld @pydanny Who am I? Daniel Greenfeld (@pydanny) Pythonista at Cartwheel Djangonaut at Revsys http://opencomparison.org Fiancé of Audrey Roy http://www.flickr.com/photos/pydanny/4442245488
  • 3. Why am I talking?
  • 5. Daniel Greenfeld @pydanny What we need
  • 6. Daniel Greenfeld @pydanny What we need • Registration of new users
  • 7. Daniel Greenfeld @pydanny What we need • Registration of new users • Authentication of existing users
  • 8. Daniel Greenfeld @pydanny What we need • Registration of new users • Authentication of existing users • Unless we are an ad-click content farm
  • 9. Daniel Greenfeld @pydanny Use OAUTH
  • 10. Daniel Greenfeld @pydanny Use OAUTH • People use Twitter/Facebook/etc
  • 11. Daniel Greenfeld @pydanny Use OAUTH • People use Twitter/Facebook/etc • Fewer passwords to memorize
  • 12. Daniel Greenfeld @pydanny Use OAUTH • People use Twitter/Facebook/etc • Fewer passwords to memorize • Our site needn’t store passwords
  • 13. Daniel Greenfeld @pydanny Use OAUTH • People use Twitter/Facebook/etc • Fewer passwords to memorize • Our site needn’t store passwords • Twitter/Facebook/etc gets to worry about security
  • 14. But OAUTH is a pain
  • 15. Everyone implements it differently
  • 16. Daniel Greenfeld @pydanny Different flavors
  • 17. Daniel Greenfeld @pydanny Different flavors • Twitter
  • 18. Daniel Greenfeld @pydanny Different flavors • Twitter • Facebook
  • 19. Daniel Greenfeld @pydanny Different flavors • Twitter • Facebook • Google
  • 20. Daniel Greenfeld @pydanny Different flavors • Twitter • Facebook • Google • Linkedin
  • 21. Daniel Greenfeld @pydanny Different flavors • Twitter • Facebook • Github (YAY!) • Google • Linkedin
  • 22. Daniel Greenfeld @pydanny Different flavors • Twitter • Facebook • Github (YAY!) • Google • Facebook ARGH • Linkedin
  • 23. Daniel Greenfeld @pydanny Different flavors • Twitter • Facebook • Github (YAY!) • Google • Facebook ARGH • Linkedin The OAUTH specification is not honored well
  • 24. Daniel Greenfeld @pydanny Different flavors • Twitter • Facebook • Github (YAY!) • Google • Facebook ARGH • Linkedin The OAUTH specification is not honored well Implementation changes are sometimes not announced
  • 25. You want a tool used by many people
  • 26. Many people means lots of eyes
  • 28. Daniel Greenfeld @pydanny Django Auth Options http://djangopackages.com/grids/g/authentication/
  • 29. Daniel Greenfeld @pydanny Django Auth Options Dozens more if you scroll http://djangopackages.com/grids/g/authentication/
  • 30. Daniel Greenfeld @pydanny Many problems • django-tastypie and Piston are for APIs • Most of these lack tests • Most of these lack documentation • Bad code smell
  • 31. They all suck for OAUTH?
  • 33. Daniel Greenfeld @pydanny django-social-auth • https://github.com/omab/django-social-auth • http://django-social-auth.rtfd.org
  • 34. Daniel Greenfeld @pydanny django-social-auth
  • 35. Daniel Greenfeld @pydanny django-social-auth • Tests!
  • 36. Daniel Greenfeld @pydanny django-social-auth • Tests! • Docs!
  • 37. Daniel Greenfeld @pydanny django-social-auth • Tests! • Docs! • Good code smell!
  • 38. Daniel Greenfeld @pydanny Statistics http://djangopackages.com/packages/p/django-social-auth/
  • 39. Daniel Greenfeld @pydanny Statistics Many downloads http://djangopackages.com/packages/p/django-social-auth/
  • 40. Daniel Greenfeld @pydanny Statistics Ongoing development Many downloads http://djangopackages.com/packages/p/django-social-auth/
  • 41. Daniel Greenfeld @pydanny Statistics Ongoing development Many downloads Many eyes on the problem http://djangopackages.com/packages/p/django-social-auth/
  • 43. Daniel Greenfeld @pydanny Get the dependency pip install django-social-auth==0.5.13
  • 44. Daniel Greenfeld @pydanny Part I: settings.py INSTALLED_APPS = ( ... 'social_auth', ... ) AUTHENTICATION_BACKENDS = ( 'social_auth.backends.contrib.github.GithubBackend', # keep this so you have that admin level backend access! 'django.contrib.auth.backends.ModelBackend', )
  • 45. Daniel Greenfeld @pydanny Part II: settings.py from django.template.defaultfilters import slugify SOCIAL_AUTH_ENABLED_BACKENDS = ('github',) SOCIAL_AUTH_COMPLETE_URL_NAME = 'socialauth_complete' SOCIAL_AUTH_ASSOCIATE_URL_NAME = 'associate_complete' SOCIAL_AUTH_DEFAULT_USERNAME = lambda u: slugify(u) SOCIAL_AUTH_EXTRA_DATA = False SOCIAL_AUTH_CHANGE_SIGNAL_ONLY = True SOCIAL_AUTH_ASSOCIATE_BY_MAIL = True # associate user via email (Usually you can just go with these as your settings)
  • 46. Daniel Greenfeld @pydanny Part III: root urls.py urlpatterns = patterns("", url('', include('social_auth.urls')), ... )
  • 47. Daniel Greenfeld @pydanny Part IV: profile/views.py from social_auth.signals import pre_update from social_auth.backends.contrib.github import GithubBackend from profiles.models. import Profile def github_user_update(sender, user, response, details, **kwargs): profile_instance, created = Profile.objects.get_or_create(user=user) profile_instance.save() return True pre_update.connect(github_user_update, sender=GithubBackend) (Not specifying this view in urls - django-social-auth does it for me)
  • 48. Daniel Greenfeld @pydanny Try it yourself! http://djangopackages.com/login/

Editor's Notes

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. \n
  27. \n
  28. \n
  29. \n
  30. \n
  31. \n
  32. \n
  33. \n
  34. \n
  35. \n
  36. \n
  37. \n
  38. \n
  39. \n
  40. \n
  41. \n
  42. \n
  43. \n