SlideShare ist ein Scribd-Unternehmen logo
1 von 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!

Weitere ähnliche Inhalte

Andere mochten auch

PyCon Philippines 2012 Keynote
PyCon Philippines 2012 KeynotePyCon Philippines 2012 Keynote
PyCon Philippines 2012 KeynoteDaniel Greenfeld
 
Intro to Data Visualizations
Intro to Data VisualizationsIntro to Data Visualizations
Intro to Data VisualizationsDaniel Greenfeld
 
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 DevelopersChristine Cheung
 
Round pegs and square holes
Round pegs and square holesRound pegs and square holes
Round pegs and square holesDaniel Greenfeld
 
Python Programming Essentials - M34 - List Comprehensions
Python Programming Essentials - M34 - List ComprehensionsPython Programming Essentials - M34 - List Comprehensions
Python Programming Essentials - M34 - List ComprehensionsP3 InfoTech Solutions Pvt. Ltd.
 
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 DevelopmentP3 InfoTech Solutions Pvt. Ltd.
 
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-pythonDaniel Greenfeld
 
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 CommerceDaniel Greenfeld
 

Andere mochten auch (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
 

Ähnlich wie Lighting talk on django-social-auth

Confessions of Joe Developer
Confessions of Joe DeveloperConfessions of Joe Developer
Confessions of Joe DeveloperDaniel Greenfeld
 
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 educationBernard Goldbach
 
Google's internal systems
Google's internal systemsGoogle's internal systems
Google's internal systemsguestcc91d4
 
Google's internal systems
Google's internal systemsGoogle's internal systems
Google's internal systemsguestcc91d4
 
Ranking in Google Discover
Ranking in Google DiscoverRanking in Google Discover
Ranking in Google DiscoverLily Ray
 

Ähnlich wie 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
 

Mehr von Daniel Greenfeld

Mehr von 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
 

Kürzlich hochgeladen

Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DaySri Ambati
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 

Kürzlich hochgeladen (20)

Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 

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/

Hinweis der Redaktion

  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