Introducing a new way to review your PRs.

Read the announcement

freelawproject / courtlistener

A fully-searchable and accessible archive of court data including growing repositories of opinions, oral arguments, judges, judicial financial records, and federal filings.

View on GitHub

19 documents · Updated Nov 24, 2026

docs / accounts-and-authentication

Accounts and authentication

CourtListener accounts give people controlled access to private features and machine access. The account system covers registration, email ownership, sign-in, password recovery, profile settings, membership status, account removal, organization SSO, OAuth, and OpenID Connect. See Platform interfaces for the wider set of entry points and API platform for API use after access is granted.

Account lifecycle

An account starts with an email-backed registration or with a stub account created by an outside process. It becomes a usable login only after the owner confirms the email address. A User is the login identity and UserProfile holds confirmation state, contact data, preferences, and account-specific settings (cl/…/models.py• L46-159).

Registration and confirmation

Registration creates a new account or upgrades a stub account. The form checks consent, a human check, blocked email domains, and username shape. It does not reveal that an email address is already in use. Instead, the system sends guidance to the address owner and keeps the response shape the same as a new signup (cl/…/views.py• L570-705, cl/…/forms.py• L102-305, cl/…/tasks.py• L98-164). When several stub accounts share an address, registration claims the most recent matching stub; other stubs do not block the signup (cl/…/views.py• L676-711, cl/…/forms.py• L259-290).

The account must prove control of its email address before sign-in, password reset, or related access can proceed. Confirmation links expire and become unusable after use. A link visit only shows a confirmation page; a POST records the confirmation. This prevents mail scanners and link prefetchers from spending the single-use key. Account mail runs outside the web request, and a confirmed account can then start the related external account sync (cl/…/views.py• L732-808, cl/…/tasks.py• L98-140).

The main account states are:

  • Stub — A placeholder can hold data from an external action but cannot act as a normal login.
  • Registered — The account has credentials and awaits email confirmation.
  • Confirmed — The owner has proved control of the email address.
  • Deleted — Private account assets are removed and the identity is scrubbed into an inactive stub.

This diagram shows the normal account path and the external path that can create a stub first.

flowchart LR
    A[External action] --> B[Stub account]
    B -->|Registration claims it| C[Registered account]
    D[New registration] --> C
    C -->|Email confirmation POST| E[Confirmed account]
    C -->|Password reset request| C
    E -->|Profile or password change| E
    E -->|Account deletion| F[Scrubbed stub]

References: cl/…/views.py• L570-808 cl/…/forms.py• L102-305 cl/…/tasks.py• L98-164 cl/…/models.py• L46-159

Account maintenance and deletion

An authenticated person can change profile data, preferences, passwords, API credentials, and email settings. An email change starts a new confirmation cycle, signs out the current session, and notifies both addresses. Sensitive actions such as deletion and API token rotation require the current account password. The password check confirms the password against the current account, not only against a matching identifier (cl/…/views.py• L298-345, cl/…/views.py• L395-462, cl/…/forms.py• L335-389).

Deletion removes private activity and credentials, while financial records such as monthly donations that must remain are disabled rather than removed. The remaining identity cannot sign in and no longer retains the person's private account data (cl/…/utils.py• L76-162, cl/…/views.py• L476-517). A person can also request a data export through the support system (cl/…/views.py• L525-567). Unconfirmed accounts receive periodic reminders and can be removed after a long period without confirmation or login (cl/…/cl_account_management.py• L16-132).

References: cl/…/views.py• L395-567 cl/…/forms.py• L335-389 cl/…/utils.py• L76-162 cl/…/cl_account_management.py• L16-132 cl/…/tests.py• L883-1070

Membership support

Membership support connects the local account to the external donor service. The profile area shows whether a membership is active and sends the person to the donor portal for joining, renewal, upgrades, payment changes, donation management, and contact updates.

Membership status

The membership page distinguishes three account-facing states:

  • Active membership — Shows the membership level and term details and offers an upgrade path.
  • Inactive membership — Shows the stored membership and payment state and offers renewal.
  • No membership — Offers a way to become a member and explains how to match the CourtListener email with the donor portal.

Membership status also shapes related product prompts. Active members receive membership links instead of join prompts, while inactive memberships continue to show join or renewal paths. Membership benefits can include higher alert limits and API usage treatment (cl/…/views.py• L279-357, cl/…/tests.py• L6132-6242).

This diagram shows how local account state directs a person to the right membership action.

flowchart LR
    A[Signed-in account] --> B{Membership state}
    B -->|Active| C[Show status and upgrade]
    B -->|Inactive| D[Show payment state and renew]
    B -->|None| E[Invite to join and match donor email]
    C --> F[Donor portal]
    D --> F
    E --> F

References: cl/…/views.py• L279-357 cl/…/membership.html• L1-89 cl/…/account-tabs.html• L1-20 cl/…/urls.py• L110-122 cl/…/tests.py• L6132-6242

Account access

The access system joins local credentials with a confirmed email state. It supports username-or-email sign-in, password changes, password reset, safe post-login redirects, and rate limits around sensitive actions (cl/…/urls.py• L27-79, cl/…/views.py• L876-907, cl/…/views.py• L1021-1045).

Sign-in and password recovery

The sign-in interface accepts a username or email address. A valid password is not enough by itself: the account must also be active and its email must be confirmed. Password reset mail goes only to confirmed accounts. Requests for known and unknown addresses use the same outward response so they do not disclose account existence (cl/…/forms.py• L418-541, cl/…/urls.py• L27-79).

The recovery path gives an unconfirmed account a way to finish verification instead of issuing a password reset link. This keeps email ownership as the gate for both sign-in and recovery. A request for an address with only unconfirmed accounts points to confirmation; a request with no account uses the generic no-account message (cl/…/forms.py• L437-541, cl/…/views.py• L811-873).

References: cl/…/forms.py• L418-541 cl/…/views.py• L732-873 cl/…/urls.py• L27-79

Email delivery safeguards

Account mail depends on a delivery record and a retry policy. Hard bounces and complaints block an address. Temporary delivery failures cause an increasing wait period. Failed messages are retried only after the address appears deliverable (cl/…/email_handlers.py• L37-235, cl/…/email_handlers.py• L326-557, cl/…/signals.py• L102-162).

The delivery record keeps enough message data to retry a failed message and can follow a user's new address when the user changes it. Duplicate delivery signals do not create duplicate retry work. This separation keeps registration and recovery flows responsive while preventing repeated delivery attempts to addresses that reject mail (cl/…/email_handlers.py• L326-557, cl/…/models.py• L311-535).

References: cl/…/email_handlers.py• L37-235 cl/…/email_handlers.py• L326-557 cl/…/signals.py• L102-162 cl/…/models.py• L311-535

Organization single sign-on

Single sign-on (SSO) lets an organization use its own identity provider while CourtListener remains the local account and access system. An organization owns its membership level and seat limit. A person's organization membership is created on first SSO access or by staff action (cl/…/models.py• L81-180, cl/…/admin.py• L66-142).

Domain access policy

An organization must prove control of an email domain before it can offer or require SSO for that domain. Domain policy can be off, optional, or required. A staff-managed email exception lets a specific address on a required-SSO domain keep password access (cl/…/models.py• L182-264, cl/…/models.py• L421-450). Public and disposable email domains cannot be claimed by an organization.

An organization is active for benefits only while it has a membership level and has not passed its benefits end date. A person who joins after the seat limit can still sign in, but does not receive the organization's benefits (cl/…/models.py• L48-79, cl/…/models.py• L148-180).

References: cl/…/models.py• L48-79 cl/…/models.py• L81-264 cl/…/models.py• L374-450 cl/…/admin.py• L66-142

Identity provider connections

Each SSO connection ties one organization to one configured identity provider. The supported protocols are OpenID Connect and SAML. Each provider has its own identity space so two providers cannot accidentally merge identities. SAML connections require signed assertions and reject sign-ins started directly at the provider (cl/…/models.py• L267-357).

The SSO outcome depends on the local account and organization state:

OutcomePlatform effect
Existing memberSign in and refresh SSO activity.
New person with a free seatCreate membership and grant organization benefits.
New person after the seat limitAllow sign-in without organization benefits.
Required-SSO address without an exceptionRefuse password access and require the provider.
Optional-SSO addressOffer SSO while retaining password access.

External identity protocols do not replace local ownership of registration, confirmation, password recovery, or the account's confirmed-email state. An email match alone does not link an external identity to a local account (cl/…/models.py• L267-357, cl/…/models.py• L374-450).

References: cl/…/models.py• L267-357 cl/…/models.py• L374-450 cl/…/admin.py• L41-64

OAuth and OpenID Connect

OAuth lets an external client obtain delegated access without receiving a user's password. OpenID Connect adds identity claims to that authorization when enabled. The platform provides authorization, token, revocation, introspection, user-info, key, discovery, and dynamic client registration endpoints under /o/ (cl/…/urls.py• L1-77, cl/…/views.py• L156-236).

Client registration

Dynamic client registration gives clients such as MCP clients a way to create an OAuth application before a user grants access. The registration endpoint is open but rate limited. The resulting client still needs a real user's authorization and consent before it can access user data (cl/…/views.py• L56-153).

The registration contract accepts the authorization-code flow and refresh tokens. It requires a code response and supports confidential or public clients. Redirect targets must use HTTPS, except for loopback HTTP targets used by local applications. Authorization-code clients use S256 PKCE. The same redirect rule applies to applications created outside dynamic registration (cl/…/api_serializers.py• L16-145, cl/…/signals.py• L1-38).

Dynamic clients may request only the api and openid scopes. Manually managed applications can use the wider scopes allowed by the platform. Discovery advertises the same dynamic-client limits so clients can learn the contract before registration (cl/…/api_serializers.py• L16-145, cl/…/validators.py• L9-30, cl/…/views.py• L179-236).

References: cl/…/views.py• L56-153 cl/…/api_serializers.py• L16-167 cl/…/signals.py• L1-38 cl/…/validators.py• L9-30

Token access and identity claims

The local account remains the source for OAuth identity data. API requests require a token with the api scope. OpenID Connect claims are released by scope: email includes the account email and its confirmation state, while profile can include the person's name fields. Empty values are omitted (cl/…/validators.py• L31-57).

Token introspection can return the local account identifier as sub, which lets a resource server link a token to the same account used by OpenID Connect. Expired grants and tokens are removed by scheduled cleanup (cl/…/views.py• L156-176, cl/…/clean_oauth_tables.py• L1-26).

References: cl/…/validators.py• L31-57 cl/…/views.py• L156-176 cl/…/clean_oauth_tables.py• L1-26

Account-facing developer tools

The authenticated profile area gives a person a place to learn about API access, view usage, manage an API token, and manage webhooks. These tools connect account identity to downstream automation without exposing another person's resources (cl/…/views.py• L281-384, cl/…/api_views.py• L27-39).

API credentials and usage

Each user receives an API token when the account is created. A person can view usage and current access limits in the profile area. Token rotation requires the current password and immediately invalidates the old token (cl/…/signals.py• L165-175, cl/…/views.py• L281-384, cl/…/urls.py• L110-118).

References: cl/…/signals.py• L165-175 cl/…/views.py• L281-384 cl/…/urls.py• L110-118

Webhook ownership

Webhooks let an authenticated user send selected platform events to an external endpoint. The account-facing interface limits listing, creation, updates, tests, and deletion to that user's own webhooks. It offers only unused event-type and version combinations. Test events are queued rather than sent inside the request (cl/…/api_views.py• L27-124, cl/…/api_views.py• L126-271, cl/…/forms.py• L562-630).

Webhook events are shown through the same owner boundary and can be filtered and paged. Webhook changes can also notify platform staff, while endpoint failures can notify the owner (cl/…/api_views.py• L274-310, cl/…/signals.py• L202-216, cl/…/tasks.py• L331-431).

References: cl/…/api_views.py• L27-310 cl/…/forms.py• L562-630 cl/…/signals.py• L202-216 cl/…/tasks.py• L331-431

Authentication audit

Authentication events provide an append-only record of important access attempts. The record captures the method and result and can link an event to a user or SSO connection. Failed unknown identifiers use a hash instead of a raw address, while successful HTTP Basic API requests are not recorded one by one (cl/…/models.py• L453-509). Staff can inspect the audit log but cannot add, edit, or delete its records (cl/…/admin.py• L145-182).

Change checklist

When these files or sections are changed, remember to consider these:

  • Keep the shared email comparison rule aligned across registration, sign-in, confirmation, and password reset.
  • Keep UserProfile.email_confirmed aligned with login permission and OAuth email_verified claims.
  • When changing registration responses, preserve the same outward path and timing for new, duplicate, unknown, and unconfirmed addresses.
  • When changing confirmation links, keep expiry, POST-only use, rate limits, and single-use invalidation aligned.
  • When changing SSO domain enforcement, review domain verification, organization benefits, seat limits, and password exceptions together.
  • When changing OAuth registration rules, update redirect validation, PKCE enforcement, discovery metadata, scope checks, and API authentication as one contract.
  • When changing account deletion, remove credentials and private assets while preserving required financial records and disabling recurring donations.
  • When changing account mail, preserve the stored-message link used by failed-email retries and the block or backoff state from SES events.
  • When changing the API profile page, update the account routes and the owner checks used by its webhook actions.
  • When changing webhook event or version choices, keep the create form, update form, available-version response, and queued test event contract aligned.
  • When changing membership status or profile navigation, keep active, inactive, and no-membership states aligned with the donor-portal actions and benefit prompts.

Important failure modes

TriggerConsequenceGuard
Login before email confirmationThe correct password still cannot create a session.The account access path checks confirmation.
A password reset is sent to an unconfirmed addressA person who does not control the account's current address could gain access.Reset mail is limited to confirmed accounts.
Registration reports that an email is already in useAn observer can test whether an address has an account.Duplicate registration uses the same success response and tells only the address owner by email.
A confirmation key is spent by a link scannerThe owner cannot confirm the account with the emailed link.GET only displays the confirmation page; POST spends and clears the key.
SSO enforcement is enabled on an unverified domainAn organization could control access for a domain it does not own.Domain enforcement requires prior verification.
A SAML connection accepts unsigned assertionsAn untrusted identity assertion could be accepted.SAML connections require signed assertions.
An OAuth redirect uses non-loopback HTTPAn authorization result could be sent to an unsafe endpoint.HTTP redirects are limited to loopback hosts at registration and save time.
An OAuth token lacks the api scopeThe API denies the request even when the token is valid.API authentication checks the required scope.
An email change keeps the old confirmation stateThe new address could receive access without proof of ownership.Email changes clear confirmation and sign out the session.
A membership with a failed payment is treated as activeThe profile can show active benefits and an upgrade path instead of renewal or join guidance.Membership actions and benefit prompts use the active state.
Account deletion removes every linked recordRequired financial history could be lost.Private assets are removed and recurring donations are disabled.
A webhook action skips the owner checkA user could read or change another user's endpoint or event log.The profile API filters objects and events by the authenticated owner.

Key files

FileWhy to read it
cl/…/models.pyDefines the local profile, email confirmation state, stub state, account settings, and email retry records.
cl/…/views.pyShows registration, confirmation, profile changes, membership status, password actions, API access, data export, and deletion flows.
cl/…/forms.pyDefines the shared account rules for email ownership, recovery, sensitive actions, and webhook choices.
cl/…/utils.pyDefines stub conversion and the boundary for account asset removal.
cl/…/email_handlers.pyExplains how failed account mail is blocked, delayed, stored, and retried.
cl/…/tasks.pyShows queued account mail, external account sync, and webhook notifications.
cl/…/signals.pyConnects new accounts and SES delivery events to tokens, profiles, and email safeguards.
cl/…/account-tabs.htmlShows the account-facing profile navigation, including the membership entry point.
cl/…/membership.htmlShows the user-facing membership states and the links to donor account actions.
cl/…/tests.pyCaptures the account deletion boundary and the membership states that shape profile access and benefits.
cl/…/models.pyDefines organizations, verified domains, identity-provider connections, memberships, and audit events.
cl/…/admin.pyShows the staff view of organization membership and the read-only authentication audit.
cl/…/api_serializers.pyDefines the safety and flow rules for dynamic OAuth client registration.
cl/…/validators.pyDefines dynamic-client scope limits and account-backed identity claims.
cl/…/views.pyShows dynamic registration, token introspection, and authorization-server discovery.
cl/…/urls.pyMaps the OAuth and OpenID Connect entry points.
cl/…/api_views.pyShows how authenticated users manage their own webhooks, event logs, and queued test events.
cl/…/urls.pyMaps sign-in, registration, profile, membership, recovery, SES, and account-facing developer routes.