Skip to content

[APPS] Add OAuth request auth support#397

Open
sdkennedy2 wants to merge 1 commit into
sdkennedy2/apps-request-auth-plumbingfrom
sdkennedy2/apps-oauth-request-auth
Open

[APPS] Add OAuth request auth support#397
sdkennedy2 wants to merge 1 commit into
sdkennedy2/apps-request-auth-plumbingfrom
sdkennedy2/apps-oauth-request-auth

Conversation

@sdkennedy2
Copy link
Copy Markdown
Collaborator

@sdkennedy2 sdkennedy2 commented Jun 4, 2026

Motivation

Apps flows should be able to use Datadog OAuth instead of requiring API/app keys. This follows the request-auth plumbing introduced in the downstack PR and keeps OAuth isolated to a second, easier-to-review change.

Changes

Adds Datadog Authorization Code + PKCE support in core request auth. Core now owns OAuth config derivation from site, browser callback handling, token exchange, refresh, OS keychain caching, and bearer header injection.

Apps adds apps.authOverride.method and APPS_AUTH_METHOD env support. When the method is oauth, Apps composes requests through withOAuthAndApiAuth; otherwise it preserves the existing API/app key path:

const doApiRequest = withOAuthAndApiAuth({
  auth,
  log,
  method: options.method,
})(withBaseUrl(`https://api.${auth.site}`)(doRequest));

The OAuth dependencies move to core because the helper is now core-owned. Apps keeps small compatibility re-exports for OAuth helpers.

QA Instructions

For manual verification, run an Apps upload with apps.authOverride.method: 'oauth' or DD_APPS_AUTH_METHOD=oauth and confirm the browser authorization flow completes and the app upload succeeds without API/app keys.

Blast Radius

This affects Apps plugin upload and local dev-server backend execution paths only when OAuth auth is selected. Existing API/app key behavior remains the default path.

Documentation

Copy link
Copy Markdown
Collaborator Author

sdkennedy2 commented Jun 4, 2026

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more

This stack of pull requests is managed by Graphite. Learn more about stacking.

@sdkennedy2 sdkennedy2 changed the title Add OAuth request auth for apps [APPS] Add OAuth request auth support Jun 4, 2026
@sdkennedy2
Copy link
Copy Markdown
Collaborator Author

@codex review
@cursor review

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ce9e4273d6

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +115 to +119
if (!oauthRequestAuthPromise) {
oauthRequestAuthPromise = authorizeOAuthRequest();
}
const requestAuth = await oauthRequestAuthPromise;
return request<T>({ ...opts, auth: requestAuth });
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Refresh OAuth auth after cached token expires

When OAuth is selected, the first successful getOAuthToken() result is cached in oauthRequestAuthPromise and reused for every later request, so long-lived contexts such as the Vite dev server middleware keep sending the same bearer token after its expiresAt has passed. Because getOAuthToken() only refreshes cached credentials when it is called, users who leave vite dev running past the access-token lifetime will get 401s on backend-function requests instead of transparently refreshing.

Useful? React with 👍 / 👎.

process.platform === 'darwin'
? { command: 'open', args: [url] }
: process.platform === 'win32'
? { command: 'cmd', args: ['/c', 'start', '', url] }
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Quote OAuth URLs before invoking cmd

On Windows, the OAuth authorization URL contains query-string & separators, but it is passed unquoted through cmd /c start; Microsoft documents that & is a special cmd character that must be escaped or quoted (https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/cmd). For Windows users choosing OAuth, cmd will split the URL at the first &, so the browser opens a truncated authorization URL and the auth flow cannot complete reliably.

Useful? React with 👍 / 👎.

@sdkennedy2 sdkennedy2 force-pushed the sdkennedy2/apps-oauth-request-auth branch from ce9e427 to c96c5fd Compare June 4, 2026 18:49
@sdkennedy2 sdkennedy2 force-pushed the sdkennedy2/apps-request-auth-plumbing branch from 05cdc83 to bf20dae Compare June 4, 2026 18:49
@sdkennedy2 sdkennedy2 marked this pull request as ready for review June 4, 2026 18:49
@sdkennedy2 sdkennedy2 requested review from a team and yoannmoinet as code owners June 4, 2026 18:49
@sdkennedy2 sdkennedy2 force-pushed the sdkennedy2/apps-oauth-request-auth branch 2 times, most recently from a3cab90 to 2392388 Compare June 4, 2026 19:38
const { auth, buildRoot } = context;

const doApiRequest = withApiAuth({
const doApiRequest = withOAuthAndApiAuth({
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This allows us to bind auth functionality to the doRequest, making it easy to swap out either just api support or api and oauth support.

@sdkennedy2 sdkennedy2 force-pushed the sdkennedy2/apps-oauth-request-auth branch from 2392388 to 9287b5b Compare June 4, 2026 19:49
@sdkennedy2 sdkennedy2 force-pushed the sdkennedy2/apps-request-auth-plumbing branch from bf20dae to 371a68b Compare June 4, 2026 19:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant