Look Behind the Curtain

Look Behind the Curtain

A Python Zagreb meetup talk about why we should not be afraid of poking into someone else's code.

382b18eebb1386e80ff7e20fd1eb784e?s=128

Senko Rašić

November 14, 2017
Tweet

Transcript

  1. Look behind the curtain Senko Rašić

  2. None
  3. None
  4. None
  5. “When the getDVRConversions is set to True it expires conversions

    automatically.” —paid support Proprietary software
  6. Open Source

  7. None
  8. None
  9. None
  10. None
  11. None
  12. None
  13. None
  14. Sign in with Google *
 *authorized users only

  15. from allauth.socialaccount.adapter import \
 DefaultSocialAccountAdapter class MyAdapter(DefaultSocialAccountAdapter): def is_open_for_signup(self, request):

    return False
  16. from allauth.socialaccount.adapter import \
 DefaultSocialAccountAdapter class MyAdapter(DefaultSocialAccountAdapter): def is_open_for_signup(self, req,

    sociallogin): return False
  17. from allauth.socialaccount.adapter import \
 DefaultSocialAccountAdapter class MyAdapter(DefaultSocialAccountAdapter): def is_open_for_signup(self, req,

    sociallogin): return False
  18. Django Developer Tragedies AllAuth won’t log in without SocialAccount, but

    won’t create SocialAccount without signup.
  19. We need to go deeper

  20. allauth.socialaccount.views.SignupView

  21. a.sa.providers.google.views.oauth2_login a.sa.providers.oauth2.views.OAuth2LoginView ↓ ↓ a.sa.providers.google.views.oauth2_callback a.sa.providers.oauth2.views.OAuth2CallbackView ↓ allauth.socialaccount.views.SignupView

  22. class OAuth2CallbackView(OAuth2View): def dispatch(self, request): … login = self.adapter.complete_login(…) …

    return complete_social_login(request, login) ↓ # allauth.socialaccount.helpers def _complete_social_login(req, sociallogin): … if sociallogin.is_existing: … else: ret = _process_signup(req, sociallogin) ↓ # allauth.socialaccount.models class SocialLogin(object): @property def is_existing(self): return self.account.pk
  23. None
  24. # a.sa.provider.google.views class GoogleOAuth2Adapter(OAuth2Adapter): def complete_login(…): … login = self.get_provider().

    \ sociallogin_from_response(…) ↓ # a.sa.providers.base class Provider(object): def sociallogin_from_response(…): … sociallogin.user = adapter.new_user(req, sociallogin) … ↓
  25. None
  26. # allauth.socialaccount.models class SocialLogin(object): @property def is_existing(self): return self.account.pk

  27. None
  28. None
  29. # allauth.socialaccount.helpers def complete_social_login(request, sociallogin): assert not sociallogin.is_existing …

  30. None
  31. None
  32. 千⾥里里之⾏行行,始於⾜足下 Debugging of thousand lines starts with a single step

  33. Thank you! @senkorasic