Historically, much of the UI used title case. This PR adds a lint check
that reports title case UI text so it can be converted to sentence case,
and converts the existing text.
- `site/scripts/check-sentence-case.mjs` runs as `pnpm
lint:sentence-case` and is part of `pnpm lint`. It reads JSX text and
string/template literals from the TypeScript AST and skips literals that
are code rather than UI text (imports, types, property names, tagged
templates, values of JSX attributes that are not displayed such as
`className` or `style`, and operands of `===`/`case` comparisons). JSX
text across inline elements and conditional JSX is checked as one
phrase. `--fix` lowercases the reported words. The checker is a
heuristic: it is not meant to model every code shape, so use a
`sentence-case-expect` comment where it guesses wrong.
- Proper nouns (Coder products, role names, third-party products,
protocols, font names) live in `PROPER_NOUNS`. For other deliberate
exceptions, a `sentence-case-expect` comment on the line above
suppresses the report and fails when that line no longer needs it.
- Existing UI text is converted to sentence case, and tests that assert
on it are updated.
- Deployment option lookups (`useDeploymentOptions`) now use CLI flags
instead of display names, so they do not depend on UI wording.
## Performance
`pnpm lint:sentence-case` takes **1.6 s** and is 2% to 4.5% of `pnpm
lint`. Measured on 82317c925e in a dev workspace (Xeon Platinum 8375C,
16 vCPUs, Node 22.23.4, TypeScript 6.0.2, warm file cache). CI buffers
the output of the lint steps, so its log has no per-step times to
compare against.
| Measurement (20 runs) | Result |
|---|---|
| Wall time | 1.64 s mean, 0.03 s standard deviation, 1.62 s to 1.71 s |
| CPU time | 3.0 s |
| Peak memory (RSS) | 154 MB, of which 116 MB is Node with `typescript`
loaded |
| Input | 1,301 of the 2,199 `.ts` and `.tsx` files in `site/src` (the
rest are excluded), 210,684 lines, 6.1 MB |
| Throughput | About 130,000 lines per second |
| Time per file | 0.5 ms median, 3 ms at the 95th percentile, 76 ms
maximum (`src/api/api.ts`, 121 KB) |
Each step of `pnpm lint`, median wall time of 5 runs:
| Step | Wall time |
|---|---|
| `lint:check` (Biome) | 0.96 s |
| `lint:oxlint` | 0.32 s |
| `lint:types` (`tsc`) | 5.8 s with its incremental cache, 45 s without
|
| `lint:circular-deps` | 5.7 s |
| `lint:compiler` | 15.6 s |
| `lint:sentence-case` | 1.6 s |
| `knip` | 6.6 s |
| All of `pnpm lint` | 37 s with the `tsc` cache, 76 s without |
<details>
<summary>Where the time goes, scaling, and limits</summary>
Phases of one run, from in-process timers. The split between parsing and
checking is approximate.
| Phase | Time | Share |
|---|---|---|
| Node startup | 0.03 s | 2% |
| Load the `typescript` module | 0.32 s | 20% |
| Find and read the files | 0.04 s | 2% |
| Parse (`ts.createSourceFile`) | 0.83 s | 52% |
| Check logic | 0.38 s | 24% |
Scaling, from synthetic inputs passed to `checkSource` (median of 3 to 5
warm runs):
- Clean input is linear in size: 0.2 ms to 0.35 ms per KB for one file
from 54 KB to 7 MB. 100,000 string literals take 0.3 s, 100,000 sibling
JSX elements take 0.8 s, and JSX nested 800 levels deep takes 10 ms.
- Conditional JSX stays bounded by the 64-variant cap: 1 to 48
conditional children in one element take at most 3.4 ms.
- Reporting and fixing add no measurable time. On the merge base with
`main` (378 reports in 175 files), a check, `--fix`, and a second
`--fix` each take 1.6 s to 1.7 s.
- The 21 unit tests run in about 30 ms, 1.7 s including Vitest startup.
Two limits, neither reachable with the current source:
- Time is quadratic in the reports for one file, because the fixed text
is rebuilt once per report. A 3.5 MB file takes 0.7 s clean and 18.0 s
with 12,800 reports. The most reports in one file on the merge base is
16.
- One JSX element with more than about 120,000 text phrases fails with
`RangeError: Maximum call stack size exceeded`, because the phrases are
spread into `push`.
</details>
---------
Co-authored-by: Jake Howell <jake@hwll.me>
8.9 KiB
title
| title |
|---|
| OAuth2 provider integration patterns |
This page covers how a client proves who it is and completes a login: the supported ways to prove identity, the standard login steps, the required Proof Key for Code Exchange (PKCE) step, and how a client finds the right web addresses to use.
- OAuth2 provider: turn on the provider and create an application
- Scopes: control what a client is allowed to access
- Token management: refresh, cancel, or delete access
- Callback URL schemes: which redirect addresses are allowed
Client authentication methods
Coder supports the following OAuth2 client authentication methods at the token endpoint (/oauth2/tokens):
client_secret_basic(recommended): HTTP Basic authentication, as defined in Request for Comments (RFC) 6749 §2.3.1. The username isclient_idand the password isclient_secret.client_secret_post: Form-based authentication whereclient_idandclient_secretare sent in the request body.none: No client secret. The client is a public client and authenticates with PKCE alone (RFC 7591 §2, OAuth 2.1 §2.1). Available only through Dynamic Client Registration, which is disabled by default, since a client's type is set when it registers and apps created through the admin UI or API are always confidential.
Coder supports both methods, so existing integrations using client_secret_post don't need to switch to client_secret_basic.
Send client_secret in the request body or in the Authorization header.
POST /oauth2/tokens and POST /oauth2/revoke reject a client_secret value in the URL query string with invalid_request, because OAuth 2.1 section 2.4.1 does not allow it there.
Refer to "invalid_request" for client_secret in the query string for the exceptions and the log line to search for.
Public clients suit native, mobile, and CLI applications that cannot keep a secret confidential. Note the redirect Uniform Resource Identifier (URI) restrictions below before choosing one.
Opening a public client on the OAuth2 applications page shows no client secrets section, since a public client has no secret to display or generate.
If you use Dynamic Client Registration (RFC 7591) and omit token_endpoint_auth_method, clients default to client_secret_basic.
To request client_secret_post, set token_endpoint_auth_method to client_secret_post in the registration request.
To register a public client, set it to none: Coder issues no client_secret, and the registration response omits that field entirely.
Important
Which redirect URI schemes and hosts a client can register, including the loopback host and port rules for public and confidential clients, is a separate restriction from client authentication. Refer to Callback URL schemes.
A client's type is fixed when it registers.
An RFC 7592 update that would move a client between public and confidential is rejected with invalid_client_metadata, since the client either holds a secret that would stop being required or has none and no way to be issued one.
Switching between client_secret_basic and client_secret_post is allowed, because both are confidential.
To change type, register a new client.
Clients registered with token_endpoint_auth_method: none before Coder honored it are stored as confidential and still require their client_secret.
Coder reports client_secret_basic for those clients so that what it reports matches what it enforces, and the mismatch clears the next time the client updates its registration using the value Coder reported.
If client authentication fails, the token endpoint returns HTTP 401 with an OAuth2 invalid_client error and a WWW-Authenticate: Basic realm="coder" response header.
Authorization code flow
Every authorization code flow requires PKCE (Proof Key for Code Exchange). Coder enforces PKCE in compliance with the OAuth 2.1 specification, for both public and confidential clients.
Note
code_verifierandcode_challengemust each be 43-128 characters from the unreserved character set[A-Za-z0-9-._~](RFC 7636 §4.1). A value outside these bounds is rejected with aninvalid_requesterror, at the token endpoint forcode_verifierand at the authorization endpoint forcode_challenge.
-
Generate a code verifier and challenge:
CODE_VERIFIER=$(openssl rand -base64 96 | tr -d '\n' | tr '+/' '-_' | tr -d '=') CODE_CHALLENGE=$(echo -n $CODE_VERIFIER | openssl dgst -sha256 -binary | base64 | tr -d "=" | tr '+/' '-_') -
Redirect users to Coder's authorization endpoint:
https://coder.example.com/oauth2/authorize? client_id=your-client-id& response_type=code& code_challenge=$CODE_CHALLENGE& code_challenge_method=S256& redirect_uri=https://yourapp.example.com/callback& state=random-string -
Exchange the authorization code for an access token, using the code verifier.
Refer to Client authentication methods for how to authenticate:
Confidential client
curl -X POST \ -u "$CLIENT_ID:$CLIENT_SECRET" \ -H "Content-Type: application/x-www-form-urlencoded" \ -d "grant_type=authorization_code" \ -d "code=$AUTH_CODE" \ -d "code_verifier=$CODE_VERIFIER" \ -d "redirect_uri=https://yourapp.example.com/callback" \ "$CODER_URL/oauth2/tokens"Public client (
token_endpoint_auth_method: none)Send
client_idin the form body and omitclient_secretentirely. The code verifier is the only proof of possession, and must satisfy RFC 7636 §4.1 (43-128 characters from[A-Za-z0-9-._~]).curl -X POST \ -H "Content-Type: application/x-www-form-urlencoded" \ -d "grant_type=authorization_code" \ -d "code=$AUTH_CODE" \ -d "client_id=$CLIENT_ID" \ -d "code_verifier=$CODE_VERIFIER" \ -d "redirect_uri=https://yourapp.example.com/callback" \ "$CODER_URL/oauth2/tokens" -
Use the access token to call Coder's API:
curl -H "Authorization: Bearer $ACCESS_TOKEN" \ "$CODER_URL/api/v2/users/me"Send the access token in the
Authorizationheader. Coder ignores an OAuth2 access token in the URL query string, as OAuth 2.1 section 5.1 requires. This endpoint requires a signed-in user, so it answers HTTP 401. Refer to HTTP 401 for an access token in the query string for endpoints that behave differently.
Discovery endpoints
Coder provides OAuth2 discovery endpoints for programmatic integration:
- Authorization Server Metadata:
GET /.well-known/oauth-authorization-server - Representational State Transfer (REST) API protected resource metadata:
GET /.well-known/oauth-protected-resource - Model Context Protocol (MCP) protected resource metadata:
GET /.well-known/oauth-protected-resource/api/experimental/mcp/http
These endpoints return server capabilities and endpoint URLs according to RFC 8414 and RFC 9728.
The REST API metadata identifies the deployment URL as its resource, while the MCP metadata identifies the full MCP endpoint URL.
Both list the deployment URL in authorization_servers and use the same authorization server metadata endpoint.
OAuth2 tokens issued for the MCP resource work with MCP tools.
token_endpoint_auth_methods_supported lists every method the token endpoint accepts, including none.
It is not gated on Dynamic Client Registration, since existing public clients still exchange tokens when new registrations are disabled.
registration_endpoint is advertised only while Dynamic Client Registration is enabled, so that field, not this one, tells a client whether it can register a new public client.
Standards compliance
This implementation follows established OAuth2 standards including RFC 6749 (OAuth2 core), RFC 7636 (PKCE), and the OAuth 2.1 draft. Coder enforces OAuth 2.1 requirements including mandatory PKCE for all authorization code grants, exact redirect URI string matching with the RFC 8252 loopback port exception, rejection of the implicit grant, and cross-site request forgery (CSRF) protections on consent pages.
Learn more
- Review Scopes for how access is bounded
- Review Token management for refresh, revocation, and deletion
- Check Troubleshooting if a request fails