Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

authorization_handler.py 937 B

1234567891011121314151617181920
  1. def handle_authenticate(context):
  2. """
  3. This function is invoked whenever a user tries to access protected HTTP resources.
  4. This function must exist and return a proper value. Otherwise the request is denied.
  5. All authentication data must be sent via using the "Authorization" header. This header
  6. will be parsed and all values will be exposed to the context.
  7. """
  8. header_value = context["header_value"] # The untouched header value.
  9. scheme = context["scheme"]
  10. parameter = context["parameter"]
  11. username = context["username"] # Only set if proper "Basic" authorization is used.
  12. password = context["password"] # Only set if proper "Basic" authorization is used.
  13. context["is_authenticated"] = True # Change this to _False_ in case of invalid credentials.
  14. # Example for an API key with proper format.
  15. if header_value == "APIKey 123456":
  16. context["is_authenticated"] = True