http.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. # -*- coding: utf-8 -*-
  2. #
  3. # This file is part of Radicale Server - Calendar Server
  4. # Copyright © 2011 Corentin Le Bail
  5. # Copyright © 2011-2012 Guillaume Ayoub
  6. #
  7. # This library is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation, either version 3 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # This library is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with Radicale. If not, see <http://www.gnu.org/licenses/>.
  19. """
  20. HTTP authentication.
  21. Make a request to an authentication server with the username/password.
  22. Anything other than a 200/201 response is considered auth failure.
  23. """
  24. import requests
  25. from .. import config, log
  26. AUTH_URL = config.get("auth", "auth_url")
  27. USER_PARAM = config.get("auth", "user_param")
  28. PASSWORD_PARAM = config.get("auth", "password_param")
  29. def is_authenticated(user, password):
  30. payload = {USER_PARAM: user, PASSWORD_PARAM: password}
  31. r = requests.post(AUTH_URL, data=payload)
  32. return r.status_code in [200, 201]