troubleshooting.rst 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. Troubleshooting
  2. ===============
  3. If you are having trouble getting django-browserid to work properly, try
  4. reading through the sections below for help on dealing with common issues.
  5. Logging Errors
  6. --------------
  7. Before you do anything else, check to see if django-browserid is logging issues
  8. by setting up a logger for ``django_browserid`` in your logging config. Here's
  9. a sample config that will log messages from django-browserid to the console:
  10. .. code-block:: python
  11. LOGGING = {
  12. 'version': 1,
  13. 'handlers': {
  14. 'console':{
  15. 'level': 'DEBUG',
  16. 'class': 'logging.StreamHandler'
  17. },
  18. },
  19. 'loggers': {
  20. 'django_browserid': {
  21. 'handlers': ['console'],
  22. 'level': 'DEBUG',
  23. }
  24. },
  25. }
  26. If you recently updated...
  27. --------------------------
  28. If you are hitting problems after updating django-browserid, check to make sure
  29. your installed copy matches the tagged version on Github. In particular,
  30. leftover ``*.pyc`` files may cause unintended side effects. This is common when
  31. installing without using a package manager like ``pip``.
  32. Nothing happens when clicking the login button
  33. ----------------------------------------------
  34. If nothing happens when you click the login button on your website, check that
  35. you've included ``api.js`` and ``browserid.js`` on your webpage:
  36. .. code-block:: html+django
  37. <script src="{% static 'browserid/api.js' %}"></script>
  38. <script src="{% static 'browserid/browserid.js' %}"></script>
  39. CSP WARN: Directive "..." violated by https://browserid.org/include.js
  40. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  41. You may see this warning in your browser's error console when your site uses
  42. `Content Security Policy`_ without making an exception for the persona.org
  43. external JavaScript include.
  44. To fix this, include https://login.persona.org in your script-src and frame-src
  45. directive. If you're using the `django-csp`_ library, the following settings
  46. will work::
  47. CSP_SCRIPT_SRC = ("'self'", 'https://login.persona.org')
  48. CSP_FRAME_SRC = ("'self'", 'https://login.persona.org')
  49. .. _Content Security Policy: https://developer.mozilla.org/en/Security/CSP
  50. .. _django-csp: https://github.com/mozilla/django-csp
  51. Login fails silently after the Persona popup closes
  52. ---------------------------------------------------
  53. There are a few reasons why login may fail without an error message after the
  54. Persona popup closes:
  55. SESSION_COOKIE_SECURE is False
  56. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  57. `SESSION_COOKIE_SECURE` controls if the `secure` flag is set on the session
  58. cookie. If set to True for site running in an environment that doesn't use
  59. HTTPS, the session cookie won't be sent by your browser because you're using an
  60. HTTP connection.
  61. The solution is to set `SESSION_COOKIE_SECURE` to False on your local instance
  62. in your settings file:
  63. .. code-block:: python
  64. SESSION_COOKIE_SECURE = False
  65. No cache configured
  66. ~~~~~~~~~~~~~~~~~~~
  67. Several projects (especially projects based on playdoh_, which uses
  68. `django-session-csrf`_) store session info in the cache rather than the
  69. database, and if your local instance has no cache configured, the session
  70. information will not be stored and login will fail silently.
  71. To solve this issue, you should configure your local instance to use an
  72. in-memory cache with the following in your local settings file::
  73. CACHES = {
  74. 'default': {
  75. 'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
  76. 'LOCATION': 'unique-snowflake'
  77. }
  78. }
  79. .. _playdoh: https://github.com/mozilla/playdoh
  80. .. _django-session-csrf: https://github.com/mozilla/django-session-csrf
  81. Login fails with an error message on a valid account
  82. ----------------------------------------------------
  83. If you see a login error page after attempting to login, but you know that
  84. your Persona account is valid and should be able to login, check for these
  85. issues:
  86. Your website uses HTTPS but django-browserid thinks it's using HTTP
  87. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  88. If you are using django-browserid behind a load balancer that uses HTTP
  89. internally for your SSL connections, you may experience failed logins. The
  90. ``request.is_secure()`` method determines if a request is using HTTPS by
  91. checking for the header specified by the `SECURE_PROXY_SSL_HEADER`_ setting. If
  92. this is unset or the header is missing, Django assumes the request uses HTTP.
  93. Because the audiences stored in
  94. :attr:`BROWSERID_AUDIENCES <django.conf.settings.BROWSERID_AUDIENCES>` include
  95. the protocol used to access the site, you may get an error when
  96. django-browserid checks the audiences against the URL from the request due to
  97. the request thinking it's not using SSL when it is.
  98. Make sure that ``SECURE_PROXY_SSL_HEADER`` is set to an appropriate value for
  99. your load balancer. An example configuration using nginx_ might look like this:
  100. .. code-block:: python
  101. # settings.py
  102. SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTOCOL', 'https')
  103. .. code-block:: nginx
  104. # nginx config
  105. location / {
  106. proxy_pass http://127.0.0.1:8000;
  107. proxy_set_header Host $host;
  108. proxy_set_header X-Real-IP $remote_addr;
  109. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  110. proxy_set_header X-Forwarded-Protocol https; # Tell django we're using https
  111. }
  112. .. _SECURE_PROXY_SSL_HEADER: https://docs.djangoproject.com/en/dev/ref/settings/#secure-proxy-ssl-header
  113. .. _nginx: http://wiki.nginx.org/
  114. Still having issues? Ask for help!
  115. ----------------------------------
  116. If your issue isn't listed above and you're having trouble tracking it down,
  117. you can try asking for help from:
  118. - The #webdev channel on `irc.mozilla.org`_,
  119. - The `dev-webdev@lists.mozilla.org`_ mailing list,
  120. - or by emailing :doc:`the maintainers </contributor/authors>` directly.
  121. .. _irc.mozilla.org: https://wiki.mozilla.org/IRC
  122. .. _dev-webdev@lists.mozilla.org: https://lists.mozilla.org/listinfo/dev-webdev