• Get Review Board
  • What's New
  • Products
  • Review Board Code review, image review, and document review
  • Documentation
  • Release Notes
  • Power Pack Enterprise integrations, reports, and enhanced document review
  • Try for 60 Days
  • Purchase
  • RBCommons Review Board as a Service, hosted by us
  • Pricing
  • RBTools Command line tools and Python API for Review Board
  • Documentation
  • Release Notes
  • Review Bot Automated code review, connecting tools you already use
  • Documentation
  • Release Notes
  • RB Gateway Manage Git and Mercurial repositories in your network
  • Documentation
  • Release Notes
  • Learn and Explore
  • What is Code Review?
  • Documentation
  • Frequently Asked Questions
  • Support Options
  • Third-Party Integrations
  • Demo
  • Review Board RBTools Power Pack Review Bot Djblets RB Gateway
    1. Djblets 5.x
    2. Version 5.x
    3. Version 4.x
    4. Version 3.x
    5. Version 2.x
    6. Version 2.0
    7. Version 1.0
    8. Version 0.9
    9. Djblets Documentation
    10. Module and Class References
    11. djblets.webapi.auth.backends.base
  • Home
  • Guides
  • Avatar Services Guides
  • Writing Avatar Services
  • Extension Guides
  • Writing Extensions
  • Testing Extensions
  • Feature Checks Guides
  • Introduction to Feature Checks
  • Writing Features
  • Writing Feature Checkers
  • Testing with Feature Checks
  • Integration Guides
  • Supporting Integrations
  • Writing Integrations
  • Privacy Compliance Guides
  • Getting and Checking Consent
  • Working with Personally Identifiable Information
  • Service Integrations
  • reCAPTCHA Guides
  • Using reCAPTCHA
  • Registries Guides
  • Writing Registries
  • Web API Guides
  • Writing Web API Resources
  • Adding OAuth2 Support
  • Module and Class References
  • djblets
  • djblets.deprecation
  • djblets.auth.forms
  • djblets.auth.ratelimit
  • djblets.auth.signals
  • djblets.auth.util
  • djblets.auth.views
  • djblets.avatars.errors
  • djblets.avatars.forms
  • djblets.avatars.registry
  • djblets.avatars.services
  • djblets.avatars.services.base
  • djblets.avatars.services.fallback
  • djblets.avatars.services.file_upload
  • djblets.avatars.services.gravatar
  • djblets.avatars.services.url
  • djblets.avatars.settings
  • djblets.cache.backend
  • djblets.cache.backend_compat
  • djblets.cache.context_processors
  • djblets.cache.errors
  • djblets.cache.forwarding_backend
  • djblets.cache.serials
  • djblets.cache.synchronizer
  • djblets.conditions
  • djblets.conditions.choices
  • djblets.conditions.conditions
  • djblets.conditions.errors
  • djblets.conditions.operators
  • djblets.conditions.values
  • djblets.configforms.forms
  • djblets.configforms.mixins
  • djblets.configforms.pages
  • djblets.configforms.registry
  • djblets.configforms.views
  • djblets.datagrid.grids
  • djblets.db.backends.mysql.base
  • djblets.db.fields
  • djblets.db.fields.base64_field
  • djblets.db.fields.comma_separated_values_field
  • djblets.db.fields.counter_field
  • djblets.db.fields.json_field
  • djblets.db.fields.modification_timestamp_field
  • djblets.db.fields.relation_counter_field
  • djblets.db.managers
  • djblets.db.query
  • djblets.db.query_catcher
  • djblets.db.query_comparator
  • djblets.db.validators
  • djblets.extensions.admin
  • djblets.extensions.errors
  • djblets.extensions.extension
  • djblets.extensions.forms
  • djblets.extensions.hooks
  • djblets.extensions.loaders
  • djblets.extensions.manager
  • djblets.extensions.middleware
  • djblets.extensions.models
  • djblets.extensions.packaging
  • djblets.extensions.resources
  • djblets.extensions.settings
  • djblets.extensions.signals
  • djblets.extensions.staticfiles
  • djblets.extensions.testing
  • djblets.extensions.testing.testcases
  • djblets.extensions.urls
  • djblets.extensions.views
  • djblets.extensions.templatetags.djblets_extensions
  • djblets.features
  • djblets.features.checkers
  • djblets.features.decorators
  • djblets.features.errors
  • djblets.features.feature
  • djblets.features.level
  • djblets.features.registry
  • djblets.features.testing
  • djblets.features.templatetags.features
  • djblets.forms.fields
  • djblets.forms.fieldsets
  • djblets.forms.forms
  • djblets.forms.forms.key_value_form
  • djblets.forms.widgets
  • djblets.gravatars
  • djblets.gravatars.templatetags.gravatars
  • djblets.http.middleware
  • djblets.http.responses
  • djblets.integrations.errors
  • djblets.integrations.forms
  • djblets.integrations.hooks
  • djblets.integrations.integration
  • djblets.integrations.manager
  • djblets.integrations.mixins
  • djblets.integrations.models
  • djblets.integrations.urls
  • djblets.integrations.views
  • djblets.log
  • djblets.log.middleware
  • djblets.log.siteconfig
  • djblets.log.urls
  • djblets.log.views
  • djblets.mail.dmarc
  • djblets.mail.message
  • djblets.mail.testing
  • djblets.mail.utils
  • djblets.markdown
  • djblets.markdown.extensions.escape_html
  • djblets.markdown.extensions.wysiwyg
  • djblets.markdown.extensions.wysiwyg_email
  • djblets.pipeline.compilers.es6
  • djblets.pipeline.compilers.less
  • djblets.pipeline.compilers.mixins
  • djblets.pipeline.compilers.rollup
  • djblets.pipeline.compilers.typescript
  • djblets.pipeline.settings
  • djblets.privacy.consent
  • djblets.privacy.consent.base
  • djblets.privacy.consent.common
  • djblets.privacy.consent.errors
  • djblets.privacy.consent.forms
  • djblets.privacy.consent.hooks
  • djblets.privacy.consent.registry
  • djblets.privacy.consent.tracker
  • djblets.privacy.models
  • djblets.privacy.pii
  • djblets.privacy.templatetags.djblets_privacy
  • djblets.recaptcha.mixins
  • djblets.recaptcha.siteconfig
  • djblets.recaptcha.templatetags.djblets_recaptcha
  • djblets.recaptcha.widgets
  • djblets.registries
  • djblets.registries.errors
  • djblets.registries.importer
  • djblets.registries.mixins
  • djblets.registries.registry
  • djblets.registries.signals
  • djblets.secrets
  • djblets.secrets.crypto
  • djblets.secrets.token_generators
  • djblets.secrets.token_generators.base
  • djblets.secrets.token_generators.legacy_sha1
  • djblets.secrets.token_generators.registry
  • djblets.secrets.token_generators.vendor_checksum
  • djblets.siteconfig
  • djblets.siteconfig.admin
  • djblets.siteconfig.context_processors
  • djblets.siteconfig.django_settings
  • djblets.siteconfig.forms
  • djblets.siteconfig.managers
  • djblets.siteconfig.middleware
  • djblets.siteconfig.models
  • djblets.siteconfig.signals
  • djblets.siteconfig.views
  • djblets.template.caches
  • djblets.template.context
  • djblets.template.loaders.conditional_cached
  • djblets.template.loaders.namespaced_app_dirs
  • djblets.testing.decorators
  • djblets.testing.testcases
  • djblets.testing.testrunners
  • djblets.urls.context_processors
  • djblets.urls.decorators
  • djblets.urls.patterns
  • djblets.urls.resolvers
  • djblets.urls.root
  • djblets.urls.staticfiles
  • djblets.util.compat.django.core.cache
  • djblets.util.compat.python.past
  • djblets.util.contextmanagers
  • djblets.util.dates
  • djblets.util.decorators
  • djblets.util.filesystem
  • djblets.util.functional
  • djblets.util.html
  • djblets.util.http
  • djblets.util.humanize
  • djblets.util.json_utils
  • djblets.util.properties
  • djblets.util.serializers
  • djblets.util.symbols
  • djblets.util.templatetags.djblets_deco
  • djblets.util.templatetags.djblets_email
  • djblets.util.templatetags.djblets_forms
  • djblets.util.templatetags.djblets_images
  • djblets.util.templatetags.djblets_js
  • djblets.util.templatetags.djblets_utils
  • djblets.util.typing
  • djblets.util.views
  • djblets.views.generic.base
  • djblets.views.generic.etag
  • djblets.webapi.auth
  • djblets.webapi.auth.backends
  • djblets.webapi.auth.backends.api_tokens
  • djblets.webapi.auth.backends.base
  • djblets.webapi.auth.backends.basic
  • djblets.webapi.auth.backends.oauth2_tokens
  • djblets.webapi.auth.views
  • djblets.webapi.decorators
  • djblets.webapi.encoders
  • djblets.webapi.errors
  • djblets.webapi.fields
  • djblets.webapi.managers
  • djblets.webapi.models
  • djblets.webapi.oauth2_scopes
  • djblets.webapi.resources
  • djblets.webapi.resources.base
  • djblets.webapi.resources.group
  • djblets.webapi.resources.registry
  • djblets.webapi.resources.root
  • djblets.webapi.resources.user
  • djblets.webapi.resources.mixins.api_tokens
  • djblets.webapi.resources.mixins.forms
  • djblets.webapi.resources.mixins.oauth2_tokens
  • djblets.webapi.resources.mixins.queries
  • djblets.webapi.responses
  • djblets.webapi.signals
  • djblets.webapi.testing
  • djblets.webapi.testing.decorators
  • djblets.webapi.testing.testcases
  • General Index
  • Python Module Index
  • Release Notes
  • djblets.webapi.auth.backends.base¶

    The base class for an API authentication backend.

    WebAPIAuthenticateResult¶

    A type alias for authentication results.

    This was the only return value supported prior to Djblets 3.2.

    Contents are in the form of:

    Tuple:
    • 0 (bool) – Whether the authentication request was successful.

    • 1 (str) – The error message to return if authentication failed.

      This can be None if it succeeded, or if it failed and the default error from LOGIN_FAILED should be used.

    • 2 (dict) – Any HTTP headers to return in the response.

      This can be None if no headers need to be returned, or if it failed and default headers from LOGIN_FAILED should be used.

    New in version 3.2.

    alias of Tuple[bool, Optional[str], Optional[Dict[str, str]]]

    WebAPICredentials¶

    A type alias for credentials passed to or from auth handlers.

    New in version 3.2.

    alias of Dict[str, Any]

    WebAPIGetCredentialsResult¶

    A type alias for the result of a get_credentials response.

    New in version 3.2.

    alias of Optional[Union[Tuple[bool, Optional[str], Optional[Dict[str, str]]], Dict[str, Any]]]

    class WebAPIAuthBackend[source]¶

    Bases: object

    Handles a form of authentication for the web API.

    This can be overridden to provide custom forms of authentication, or to support multiple types of authentication.

    More than one authentication backend can be used with the web API. In that case, the client can make the determination about which to use.

    Auth backends generally need to only override the get_credentials() method, though more specialized ones may override other methods as well.

    They must also provide www_auth_scheme which is a WWW-Authenticate scheme value.

    www_auth_scheme: Optional[str] = None¶

    The auth scheme used in the WWW-Authenticate header.

    Type:

    str

    SENSITIVE_CREDENTIALS_RE = re.compile('api|token|key|secret|password|signature', re.IGNORECASE)[source]¶

    A regex of sensitive entries in the credentials dictionary.

    By default, this excludes keys containing “api”, “token”, “key”, “secret”, “password”, or “signature” anywhere in the name, in any casing.

    This can be extended for other sensitive information.

    get_auth_headers(request: HttpRequest) → Dict[str, Any][source]¶

    Return extra authentication headers for the response.

    Parameters:

    request (django.http.HttpRequest) – The HTTP request from the client.

    Returns:

    The authentication headers (defaults to empty).

    Return type:

    dict

    authenticate(request: HttpRequest, **kwargs) → Optional[Tuple[bool, Optional[str], Optional[Dict[str, str]]]][source]¶

    Authenticate a request against this auth backend.

    This will fetch the credentials and attempt an authentication against those credentials.

    This function must return None to indicate it should be skipped and another backend should be tried, or a tuple indicating the success/failure and additional details for the client.

    Parameters:

    request (django.http.HttpRequest) – The HTTP request from the client.

    Returns:

    See WebAPIAuthenticateResult for details on the format for the returned type value.

    If the backend should be skipped, this will return None.

    Return type:

    tuple or None

    get_credentials(request: HttpRequest) → Optional[Union[Tuple[bool, Optional[str], Optional[Dict[str, str]]], Dict[str, Any]]][source]¶

    Return credentials provided in the request.

    This returns a dictionary of all credentials necessary for this auth backend. By default, this expects username and password, though more specialized auth backends may provide other information. These credentials will be passed to login_with_credentials().

    This function must be implemented by the subclass.

    Parameters:

    request (django.http.HttpRequest) – The HTTP request from the client.

    Returns:

    A dictionary of credential information.

    Return type:

    dict

    login_with_credentials(request: HttpRequest, **credentials) → Tuple[bool, Optional[str], Optional[Dict[str, str]]][source]¶

    Log in against the main authentication backends.

    This takes the provided credentials from the request (as returned by get_credentials()) and attempts a login against the main authentication backends used by Django.

    Parameters:
    • request (django.http.HttpRequest) – The HTTP request from the client.

    • credentials (dict) – All credentials provided by get_credentials().

    Returns:

    See the return type in authenticate().

    Return type:

    tuple or None

    validate_credentials(request: HttpRequest, **credentials) → Optional[Tuple[bool, Optional[str], Optional[Dict[str, str]]]][source]¶

    Validate that credentials are valid.

    This is called before we attempt to authenticate with the credentials, and can short-circuit the rest of the authentication process, returning a result tuple if desired. If None is returned, authentication proceeds as normal.

    By default, this will attempt to bypass authentication if the current user is already logged in and matches the authenticated user (if and only if username appears in the credentials).

    Subclasses can override this to provide more specific behavior for their sets of credentials, or to disable this entirely.

    Parameters:
    • request (django.http.HttpRequest) – The HTTP request from the client.

    • credentials (dict) – All credentials provided by get_credentials().

    Returns:

    See the return type in authenticate().

    Return type:

    tuple or None

    clean_credentials_for_display(credentials: Dict[str, Any]) → Dict[str, Any][source]¶

    Clean up a credentials dictionary, removing sensitive information.

    This will take a credentials dictionary and mask anything sensitive, preparing it for output to a log file.

    Parameters:

    credentials (dict) – A dictionary of credentials provided for authentication.

    Returns:

    A sanitized dictionary of credentials, for display purposes.

    Return type:

    dict

    __annotations__ = {'www_auth_scheme': 'Optional[str]'}¶

    Keep up with the latest Review Board releases, security updates, and helpful information.

    About
    News
    Demo
    RBCommons Hosting
    Integrations
    Happy Users
    Support Options
    Documentation
    FAQ
    User Manual
    RBTools
    Administration Guide
    Power Pack
    Release Notes
    Downloads
    Review Board
    RBTools
    Djblets
    Power Pack
    Package Store
    PGP Signatures
    Contributing
    Bug Tracker
    Submit Patches
    Development Setup
    Wiki
    Follow Us
    Mailing Lists
    Reddit
    Twitter
    Mastodon
    Facebook
    YouTube

    Copyright © 2006-2025 Beanbag, Inc. All rights reserved.

    Terms of Service — Privacy Policy — AI Ethics Policy — Branding

    On this page

    • [Top]
    • WebAPIAuthenticateResult
    • WebAPICredentials
    • WebAPIGetCredentialsResult
    • WebAPIAuthBackend
      • WebAPIAuthBackend.www_auth_scheme
      • WebAPIAuthBackend.SENSITIVE_CREDENTIALS_RE
      • WebAPIAuthBackend.get_auth_headers()
      • WebAPIAuthBackend.authenticate()
      • WebAPIAuthBackend.get_credentials()
      • WebAPIAuthBackend.login_with_credentials()
      • WebAPIAuthBackend.validate_credentials()
      • WebAPIAuthBackend.clean_credentials_for_display()
      • WebAPIAuthBackend.__annotations__